@timardex/cluemart-server-shared 4.2.1 → 5.1.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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
2
- import { AdType, AdDailyPriceType, AdBookingType, AdMetricsType, ChatType, ParticipantType, ChatMessageType, NotificationType, CreateBulkNotificationInput, EnumUserRole, BillingCatalogEntryType, BillingCatalogPriceHistoryEntry, EnumBillingPeriod, EnumUserLicence, BILLING_CATALOG_KEYS, ReportChatUser, OwnerType, AssociateType, EnumAssociateStatus, Category, ResourceContactDetailsType, ResourceImageType, RelatedPostType, SocialMediaType, PosterUsageType, SocialShareResourceType, TermsAgreement, DateTimeType, LocationGeoType, LocationType, UserLicenceType, GoogleImportedMarket, AiImportedMarket, EnumImportedMarketDeactivationReason, EnumAiImportRunStatus, AiImportUsage, ScrapeSite, PushTokenType, RelationType, RelationDate, ResourceActivityType, StripeSubscription, UserActivityEvent, UserType, VendorType, VendorProductList, VendorInfoType, UnregisteredVendorInvitationType, UnregisteredVendorType, EventType, EventInfoType, StallType, RefundPolicy, PartnerType, PostType, PostContentType, PostResource, AppSettingsType, GameDocType, GameType, SchoolType, AffiliateType, AffiliateResourceType, AffiliateRewardType, CouponType, CouponDataType, CouponParticipantUserType, EnumResourceType, PromoCodeType, EnumAffiliateRewardType, EnumPointType, UserOverallPointsEntry, EventListItemType, DateTimeWithPriceType, EnumNotificationResourceType, EnumNotificationType, LicenceExpiryDate } from '@timardex/cluemart-shared';
2
+ import { AdType, AdDailyPriceType, AdBookingType, AdMetricsType, ChatType, ParticipantType, ChatMessageType, NotificationType, CreateBulkNotificationInput, EnumUserRole, BillingCatalogEntryType, BillingCatalogPriceHistoryEntry, EnumBillingPeriod, EnumUserLicence, BILLING_CATALOG_KEYS, ReportChatUser, OwnerType, AssociateType, EnumAssociateStatus, Category, ResourceContactDetailsType, ResourceImageType, RelatedPostType, SocialMediaType, PosterUsageType, SocialShareResourceType, TermsAgreement, DateTimeType, LocationGeoType, LocationType, UserLicenceType, GoogleImportedMarket, EnumImportedMarketDeactivationReason, AiImportedMarket, EnumAiImportRunStatus, AiImportUsage, ScrapeSite, PushTokenType, RelationType, RelationDate, ResourceActivityType, StripeSubscription, UserActivityEvent, UserType, VendorType, VendorProductList, VendorInfoType, UnregisteredVendorInvitationType, UnregisteredVendorType, EventType, EventInfoType, StallType, RefundPolicy, PartnerType, PostType, PostContentType, PostResource, AppSettingsType, GameDocType, GameType, SchoolType, AffiliateType, AffiliateResourceType, AffiliateRewardType, CouponType, CouponDataType, CouponParticipantUserType, EnumResourceType, PromoCodeType, EnumAffiliateRewardType, EnumPointType, UserOverallPointsEntry, DateTimeWithPriceType, EnumNotificationResourceType, EnumNotificationType, LicenceExpiryDate } from '@timardex/cluemart-shared';
3
3
  export { updateSingleDateTimeStatus } from '@timardex/cluemart-shared';
4
4
  import * as mongoose from 'mongoose';
5
5
  import mongoose__default from 'mongoose';
@@ -522,6 +522,14 @@ declare const baseResourceFields: {
522
522
  type SchemaGoogleImportedMarket = Omit<GoogleImportedMarket, "eventId" | "claimedByUserId"> & {
523
523
  eventId?: mongoose__default.Types.ObjectId;
524
524
  claimedByUserId?: mongoose__default.Types.ObjectId;
525
+ /**
526
+ * Why an inactive market was switched off: `STALE` when the source reported the
527
+ * place as no longer operational (only the crawler may switch it back on),
528
+ * `ADMIN` when an admin did it (the crawler must leave it alone). Absent on
529
+ * markets deactivated before the reason existed, which are treated as
530
+ * admin-owned — the conservative default.
531
+ */
532
+ deactivatedReason?: EnumImportedMarketDeactivationReason | null;
525
533
  /** Lowercase `name` mirror for prefix type-ahead (see searchNamePlugin). */
526
534
  searchName?: string;
527
535
  /** Indexed earliest `dateTime` start instant for chronological pagination. */
@@ -530,6 +538,14 @@ type SchemaGoogleImportedMarket = Omit<GoogleImportedMarket, "eventId" | "claime
530
538
  declare const GoogleImportedMarketModel: mongoose__default.Model<SchemaGoogleImportedMarket, {}, {}, {}, mongoose__default.Document<unknown, {}, SchemaGoogleImportedMarket, {}, {}> & Omit<GoogleImportedMarket, "eventId" | "claimedByUserId"> & {
531
539
  eventId?: mongoose__default.Types.ObjectId;
532
540
  claimedByUserId?: mongoose__default.Types.ObjectId;
541
+ /**
542
+ * Why an inactive market was switched off: `STALE` when the source reported the
543
+ * place as no longer operational (only the crawler may switch it back on),
544
+ * `ADMIN` when an admin did it (the crawler must leave it alone). Absent on
545
+ * markets deactivated before the reason existed, which are treated as
546
+ * admin-owned — the conservative default.
547
+ */
548
+ deactivatedReason?: EnumImportedMarketDeactivationReason | null;
533
549
  /** Lowercase `name` mirror for prefix type-ahead (see searchNamePlugin). */
534
550
  searchName?: string;
535
551
  /** Indexed earliest `dateTime` start instant for chronological pagination. */
@@ -1637,20 +1653,109 @@ declare function dedupeArchivedSlotsByStartDateTime(slots: DateTimeType[]): Date
1637
1653
  */
1638
1654
  declare function persistArchivedEventDates(eventId: ObjectId | string, slots: DateTimeType[]): Promise<void>;
1639
1655
 
1640
- type EventOrMarket = (Pick<EventListItemType, "_id" | "name" | "dateTime"> & {
1641
- /** Present on owned EventModel docs; absent on Google-imported markets. */
1656
+ /** Which collection an `EVENT`-typed id resolved to, together with its document. */
1657
+ type EventOrImportedMarketMatch = {
1658
+ doc: SchemaAiImportedMarket;
1659
+ kind: "ai";
1660
+ } | {
1661
+ doc: SchemaEventType;
1662
+ kind: "event";
1663
+ } | {
1664
+ doc: SchemaGoogleImportedMarket;
1665
+ kind: "google";
1666
+ };
1667
+ /**
1668
+ * What an ordinary caller reads off an Event: its identity, the visibility
1669
+ * flags, the name a notification needs, the owner the "no activity on your own
1670
+ * resource" guard needs, and the slots a check-in is validated against.
1671
+ */
1672
+ type EventReference = Pick<SchemaEventType, "_id" | "active" | "dateTime" | "deletedAt" | "name"> & {
1642
1673
  owner?: SchemaOwnerType;
1643
- }) | null;
1674
+ };
1675
+ /** The same subset for an imported market, which has no owner. */
1676
+ type ImportedMarketReference = Pick<SchemaGoogleImportedMarket, "_id" | "active" | "dateTime" | "deletedAt" | "name">;
1677
+ type AiImportedMarketReference = ImportedMarketReference & {
1678
+ reviewStatus: SchemaAiImportedMarket["reviewStatus"];
1679
+ };
1680
+ /** Which collection an `EVENT`-typed id resolved to, with the fields an ordinary caller reads. */
1681
+ type EventOrImportedMarketReferenceMatch = {
1682
+ doc: AiImportedMarketReference;
1683
+ kind: "ai";
1684
+ } | {
1685
+ doc: EventReference;
1686
+ kind: "event";
1687
+ } | {
1688
+ doc: ImportedMarketReference;
1689
+ kind: "google";
1690
+ };
1691
+ type EventOrImportedMarketLookupOptions = {
1692
+ /**
1693
+ * Also return markets the public can no longer reach: inactive and/or
1694
+ * soft-deleted ones.
1695
+ *
1696
+ * Reserved for the admin flows that have to see them, because every admin
1697
+ * action starts from a market in one of those states: the detail screen
1698
+ * renders activation for an inactive market, the soft delete is only offered
1699
+ * once a market is inactive, and the hard delete only runs on a soft-deleted
1700
+ * one. Every ordinary lookup (check-ins, favourites, interest/going, activity)
1701
+ * must keep the default, otherwise a user could act on a market that has been
1702
+ * taken down or switched off.
1703
+ */
1704
+ includeDeleted?: boolean;
1705
+ };
1644
1706
  /**
1645
- * This function attempts to find an Event, Google Imported Market, or AI
1646
- * Imported Market by the given resource ID.
1647
- * It first normalizes the resource ID to a string format, then performs parallel queries to all three collections.
1648
- * If an Event is found, it returns that; otherwise it checks the imported-market collections and returns the first match.
1649
- * If none is found, it returns null.
1650
- * @param resourceId - The ID of the resource to find, which can be an ObjectId, string, null, or undefined.
1651
- * @returns A promise that resolves to either an Event or an Imported Market object containing _id, name, dateTime, and owner (events only), or null if not found.
1707
+ * Resolves an `EVENT`-typed id for the frequent ordinary flows: check-ins,
1708
+ * favourites, interest/going, resource activity and the cron notifications.
1709
+ *
1710
+ * This is the single definition of that lookup **and** of its visibility rule:
1711
+ * by default it only returns live rows (active and not soft-deleted, the same
1712
+ * pair the public lists and the activity feeds filter on), and the admin flows
1713
+ * that must see an inactive or retired market pass `includeDeleted`.
1714
+ *
1715
+ * It returns only the `EventReference` fields. These run on every user action, so
1716
+ * hydrating descriptions, images, locations or association metadata would
1717
+ * transfer and retain whole documents just to read an id and a date list. The
1718
+ * screens and admin flows that render a market use
1719
+ * `findEventOrImportedMarketDetailsById`.
1720
+ *
1721
+ * @param resourceId - The id to resolve: ObjectId, string, or nothing.
1722
+ * @param options - `includeDeleted` for the admin hard-delete/detail flows.
1723
+ * @returns The matched collection plus the fields an ordinary caller reads, or null.
1724
+ */
1725
+ declare function findEventOrImportedMarketById(resourceId: ObjectId | string | null | undefined, options?: EventOrImportedMarketLookupOptions): Promise<EventOrImportedMarketReferenceMatch | null>;
1726
+ /**
1727
+ * Resolves an `EVENT`-typed id to the whole document, for the flows that render
1728
+ * it: the market detail screen (which returns it to the client) and the admin
1729
+ * mutations (activation, soft delete, hard delete with its asset folder).
1730
+ *
1731
+ * Same collections and same visibility rule as
1732
+ * `findEventOrImportedMarketById`; only the projection differs, so anything that
1733
+ * resolves there resolves here too. The caller still decides what its own
1734
+ * audience may see (e.g. `getEvent` runs `canUserViewResourceById`).
1735
+ */
1736
+ declare function findEventOrImportedMarketDetailsById(resourceId: ObjectId | string | null | undefined, options?: EventOrImportedMarketLookupOptions): Promise<EventOrImportedMarketMatch | null>;
1737
+
1738
+ /**
1739
+ * What "the public may still see this resource" means, as a Mongo filter.
1740
+ *
1741
+ * Events, Google imports and AI imports all carry the same `active` +
1742
+ * `deletedAt` pair, so the public lists, the user activity feeds and the
1743
+ * by-id lookup all reuse this one definition instead of restating the pair.
1744
+ */
1745
+ declare const LIVE_RESOURCE_FILTER: {
1746
+ readonly active: true;
1747
+ readonly deletedAt: null;
1748
+ };
1749
+ /**
1750
+ * The JavaScript form of `LIVE_RESOURCE_FILTER`, for rows already loaded.
1751
+ *
1752
+ * A missing `active` counts as inactive: the Mongo filter does not match absent
1753
+ * fields either, so the two forms agree.
1652
1754
  */
1653
- declare function findEventOrImportedMarketById(resourceId: ObjectId | string | null | undefined): Promise<EventOrMarket>;
1755
+ declare function isLiveResource(resource: {
1756
+ active?: boolean | null;
1757
+ deletedAt?: Date | null;
1758
+ }): boolean;
1654
1759
 
1655
1760
  type EventDateSlot = Pick<DateTimeType$1, "startDate" | "startTime">;
1656
1761
  type StartedDateSlot = Pick<DateTimeType$1, "dateStatus" | "startDate" | "startTime">;
@@ -2004,4 +2109,4 @@ declare function hasActiveProLicenceForResource({ includeStripeProtected, userId
2004
2109
  resourceType: EnumResourceType;
2005
2110
  }): Promise<boolean>;
2006
2111
 
2007
- export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, AI_IMPORT_RUN_LOCK_KEY, APP_SETTINGS_ID, type ActiveLicenceOptions, AdBillingCatalogModel, AdBookingModel, AdMetricsModel, AdModel, AdPurchaseModel, AffiliateModel, AiImportRunLockModel, AiImportRunModel, type AiImportRunStatus, type AiImportSiteResult, AiImportedMarketModel, AppSettingModel, type AssociableResourceType, AssociateTypeSchema, AuthHandoffTokenModel, type AuthHandoffTokenType, type AuthTokenClient, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, type DetachedAssociateGrants, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, type IndexBuildFailure, type IndexableModel, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, type ReconcileAssociateGrantsResult, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SCRAPE_SITES_CONFIG_ID, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAiImportRun, type SchemaAiImportedMarket, type SchemaAppSettingsType, type SchemaAssociateType, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventDateArchiveType, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaImpersonationAuditType, type SchemaImpersonationSessionType, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserAssociatedResourcesType, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, ScrapeSiteConfigModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, acceptedAssociateUserIds, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, detachAssociateGrantsForResources, detachStaleAssociateGrants, detachUsersFromResource, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureDatabaseIndexes, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getActiveLicenceForResource, getAssociateAccessMeta, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getUserIdsWithActiveProLicence, getVendorResourceInfo, grantAssociateGrants, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasActiveProLicenceForResource, hasValidLicence, isAssociableResourceType, isProLicence, isProtectedByCurrentStripeSubscription, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, reconcileAssociateGrants, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToCanceled, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
2112
+ export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, AI_IMPORT_RUN_LOCK_KEY, APP_SETTINGS_ID, type ActiveLicenceOptions, AdBillingCatalogModel, AdBookingModel, AdMetricsModel, AdModel, AdPurchaseModel, AffiliateModel, AiImportRunLockModel, AiImportRunModel, type AiImportRunStatus, type AiImportSiteResult, AiImportedMarketModel, type AiImportedMarketReference, AppSettingModel, type AssociableResourceType, AssociateTypeSchema, AuthHandoffTokenModel, type AuthHandoffTokenType, type AuthTokenClient, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, type DetachedAssociateGrants, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, type EventOrImportedMarketLookupOptions, type EventOrImportedMarketMatch, type EventOrImportedMarketReferenceMatch, type EventReference, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, type ImportedMarketReference, type IndexBuildFailure, type IndexableModel, LIVE_RESOURCE_FILTER, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, type ReconcileAssociateGrantsResult, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SCRAPE_SITES_CONFIG_ID, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAiImportRun, type SchemaAiImportedMarket, type SchemaAppSettingsType, type SchemaAssociateType, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventDateArchiveType, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaImpersonationAuditType, type SchemaImpersonationSessionType, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserAssociatedResourcesType, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, ScrapeSiteConfigModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, acceptedAssociateUserIds, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, detachAssociateGrantsForResources, detachStaleAssociateGrants, detachUsersFromResource, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureDatabaseIndexes, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, findEventOrImportedMarketDetailsById, getActiveLicenceForResource, getAssociateAccessMeta, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getUserIdsWithActiveProLicence, getVendorResourceInfo, grantAssociateGrants, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasActiveProLicenceForResource, hasValidLicence, isAssociableResourceType, isLiveResource, isProLicence, isProtectedByCurrentStripeSubscription, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, reconcileAssociateGrants, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToCanceled, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
2
- import { AdType, AdDailyPriceType, AdBookingType, AdMetricsType, ChatType, ParticipantType, ChatMessageType, NotificationType, CreateBulkNotificationInput, EnumUserRole, BillingCatalogEntryType, BillingCatalogPriceHistoryEntry, EnumBillingPeriod, EnumUserLicence, BILLING_CATALOG_KEYS, ReportChatUser, OwnerType, AssociateType, EnumAssociateStatus, Category, ResourceContactDetailsType, ResourceImageType, RelatedPostType, SocialMediaType, PosterUsageType, SocialShareResourceType, TermsAgreement, DateTimeType, LocationGeoType, LocationType, UserLicenceType, GoogleImportedMarket, AiImportedMarket, EnumImportedMarketDeactivationReason, EnumAiImportRunStatus, AiImportUsage, ScrapeSite, PushTokenType, RelationType, RelationDate, ResourceActivityType, StripeSubscription, UserActivityEvent, UserType, VendorType, VendorProductList, VendorInfoType, UnregisteredVendorInvitationType, UnregisteredVendorType, EventType, EventInfoType, StallType, RefundPolicy, PartnerType, PostType, PostContentType, PostResource, AppSettingsType, GameDocType, GameType, SchoolType, AffiliateType, AffiliateResourceType, AffiliateRewardType, CouponType, CouponDataType, CouponParticipantUserType, EnumResourceType, PromoCodeType, EnumAffiliateRewardType, EnumPointType, UserOverallPointsEntry, EventListItemType, DateTimeWithPriceType, EnumNotificationResourceType, EnumNotificationType, LicenceExpiryDate } from '@timardex/cluemart-shared';
2
+ import { AdType, AdDailyPriceType, AdBookingType, AdMetricsType, ChatType, ParticipantType, ChatMessageType, NotificationType, CreateBulkNotificationInput, EnumUserRole, BillingCatalogEntryType, BillingCatalogPriceHistoryEntry, EnumBillingPeriod, EnumUserLicence, BILLING_CATALOG_KEYS, ReportChatUser, OwnerType, AssociateType, EnumAssociateStatus, Category, ResourceContactDetailsType, ResourceImageType, RelatedPostType, SocialMediaType, PosterUsageType, SocialShareResourceType, TermsAgreement, DateTimeType, LocationGeoType, LocationType, UserLicenceType, GoogleImportedMarket, EnumImportedMarketDeactivationReason, AiImportedMarket, EnumAiImportRunStatus, AiImportUsage, ScrapeSite, PushTokenType, RelationType, RelationDate, ResourceActivityType, StripeSubscription, UserActivityEvent, UserType, VendorType, VendorProductList, VendorInfoType, UnregisteredVendorInvitationType, UnregisteredVendorType, EventType, EventInfoType, StallType, RefundPolicy, PartnerType, PostType, PostContentType, PostResource, AppSettingsType, GameDocType, GameType, SchoolType, AffiliateType, AffiliateResourceType, AffiliateRewardType, CouponType, CouponDataType, CouponParticipantUserType, EnumResourceType, PromoCodeType, EnumAffiliateRewardType, EnumPointType, UserOverallPointsEntry, DateTimeWithPriceType, EnumNotificationResourceType, EnumNotificationType, LicenceExpiryDate } from '@timardex/cluemart-shared';
3
3
  export { updateSingleDateTimeStatus } from '@timardex/cluemart-shared';
4
4
  import * as mongoose from 'mongoose';
5
5
  import mongoose__default from 'mongoose';
@@ -522,6 +522,14 @@ declare const baseResourceFields: {
522
522
  type SchemaGoogleImportedMarket = Omit<GoogleImportedMarket, "eventId" | "claimedByUserId"> & {
523
523
  eventId?: mongoose__default.Types.ObjectId;
524
524
  claimedByUserId?: mongoose__default.Types.ObjectId;
525
+ /**
526
+ * Why an inactive market was switched off: `STALE` when the source reported the
527
+ * place as no longer operational (only the crawler may switch it back on),
528
+ * `ADMIN` when an admin did it (the crawler must leave it alone). Absent on
529
+ * markets deactivated before the reason existed, which are treated as
530
+ * admin-owned — the conservative default.
531
+ */
532
+ deactivatedReason?: EnumImportedMarketDeactivationReason | null;
525
533
  /** Lowercase `name` mirror for prefix type-ahead (see searchNamePlugin). */
526
534
  searchName?: string;
527
535
  /** Indexed earliest `dateTime` start instant for chronological pagination. */
@@ -530,6 +538,14 @@ type SchemaGoogleImportedMarket = Omit<GoogleImportedMarket, "eventId" | "claime
530
538
  declare const GoogleImportedMarketModel: mongoose__default.Model<SchemaGoogleImportedMarket, {}, {}, {}, mongoose__default.Document<unknown, {}, SchemaGoogleImportedMarket, {}, {}> & Omit<GoogleImportedMarket, "eventId" | "claimedByUserId"> & {
531
539
  eventId?: mongoose__default.Types.ObjectId;
532
540
  claimedByUserId?: mongoose__default.Types.ObjectId;
541
+ /**
542
+ * Why an inactive market was switched off: `STALE` when the source reported the
543
+ * place as no longer operational (only the crawler may switch it back on),
544
+ * `ADMIN` when an admin did it (the crawler must leave it alone). Absent on
545
+ * markets deactivated before the reason existed, which are treated as
546
+ * admin-owned — the conservative default.
547
+ */
548
+ deactivatedReason?: EnumImportedMarketDeactivationReason | null;
533
549
  /** Lowercase `name` mirror for prefix type-ahead (see searchNamePlugin). */
534
550
  searchName?: string;
535
551
  /** Indexed earliest `dateTime` start instant for chronological pagination. */
@@ -1637,20 +1653,109 @@ declare function dedupeArchivedSlotsByStartDateTime(slots: DateTimeType[]): Date
1637
1653
  */
1638
1654
  declare function persistArchivedEventDates(eventId: ObjectId | string, slots: DateTimeType[]): Promise<void>;
1639
1655
 
1640
- type EventOrMarket = (Pick<EventListItemType, "_id" | "name" | "dateTime"> & {
1641
- /** Present on owned EventModel docs; absent on Google-imported markets. */
1656
+ /** Which collection an `EVENT`-typed id resolved to, together with its document. */
1657
+ type EventOrImportedMarketMatch = {
1658
+ doc: SchemaAiImportedMarket;
1659
+ kind: "ai";
1660
+ } | {
1661
+ doc: SchemaEventType;
1662
+ kind: "event";
1663
+ } | {
1664
+ doc: SchemaGoogleImportedMarket;
1665
+ kind: "google";
1666
+ };
1667
+ /**
1668
+ * What an ordinary caller reads off an Event: its identity, the visibility
1669
+ * flags, the name a notification needs, the owner the "no activity on your own
1670
+ * resource" guard needs, and the slots a check-in is validated against.
1671
+ */
1672
+ type EventReference = Pick<SchemaEventType, "_id" | "active" | "dateTime" | "deletedAt" | "name"> & {
1642
1673
  owner?: SchemaOwnerType;
1643
- }) | null;
1674
+ };
1675
+ /** The same subset for an imported market, which has no owner. */
1676
+ type ImportedMarketReference = Pick<SchemaGoogleImportedMarket, "_id" | "active" | "dateTime" | "deletedAt" | "name">;
1677
+ type AiImportedMarketReference = ImportedMarketReference & {
1678
+ reviewStatus: SchemaAiImportedMarket["reviewStatus"];
1679
+ };
1680
+ /** Which collection an `EVENT`-typed id resolved to, with the fields an ordinary caller reads. */
1681
+ type EventOrImportedMarketReferenceMatch = {
1682
+ doc: AiImportedMarketReference;
1683
+ kind: "ai";
1684
+ } | {
1685
+ doc: EventReference;
1686
+ kind: "event";
1687
+ } | {
1688
+ doc: ImportedMarketReference;
1689
+ kind: "google";
1690
+ };
1691
+ type EventOrImportedMarketLookupOptions = {
1692
+ /**
1693
+ * Also return markets the public can no longer reach: inactive and/or
1694
+ * soft-deleted ones.
1695
+ *
1696
+ * Reserved for the admin flows that have to see them, because every admin
1697
+ * action starts from a market in one of those states: the detail screen
1698
+ * renders activation for an inactive market, the soft delete is only offered
1699
+ * once a market is inactive, and the hard delete only runs on a soft-deleted
1700
+ * one. Every ordinary lookup (check-ins, favourites, interest/going, activity)
1701
+ * must keep the default, otherwise a user could act on a market that has been
1702
+ * taken down or switched off.
1703
+ */
1704
+ includeDeleted?: boolean;
1705
+ };
1644
1706
  /**
1645
- * This function attempts to find an Event, Google Imported Market, or AI
1646
- * Imported Market by the given resource ID.
1647
- * It first normalizes the resource ID to a string format, then performs parallel queries to all three collections.
1648
- * If an Event is found, it returns that; otherwise it checks the imported-market collections and returns the first match.
1649
- * If none is found, it returns null.
1650
- * @param resourceId - The ID of the resource to find, which can be an ObjectId, string, null, or undefined.
1651
- * @returns A promise that resolves to either an Event or an Imported Market object containing _id, name, dateTime, and owner (events only), or null if not found.
1707
+ * Resolves an `EVENT`-typed id for the frequent ordinary flows: check-ins,
1708
+ * favourites, interest/going, resource activity and the cron notifications.
1709
+ *
1710
+ * This is the single definition of that lookup **and** of its visibility rule:
1711
+ * by default it only returns live rows (active and not soft-deleted, the same
1712
+ * pair the public lists and the activity feeds filter on), and the admin flows
1713
+ * that must see an inactive or retired market pass `includeDeleted`.
1714
+ *
1715
+ * It returns only the `EventReference` fields. These run on every user action, so
1716
+ * hydrating descriptions, images, locations or association metadata would
1717
+ * transfer and retain whole documents just to read an id and a date list. The
1718
+ * screens and admin flows that render a market use
1719
+ * `findEventOrImportedMarketDetailsById`.
1720
+ *
1721
+ * @param resourceId - The id to resolve: ObjectId, string, or nothing.
1722
+ * @param options - `includeDeleted` for the admin hard-delete/detail flows.
1723
+ * @returns The matched collection plus the fields an ordinary caller reads, or null.
1724
+ */
1725
+ declare function findEventOrImportedMarketById(resourceId: ObjectId | string | null | undefined, options?: EventOrImportedMarketLookupOptions): Promise<EventOrImportedMarketReferenceMatch | null>;
1726
+ /**
1727
+ * Resolves an `EVENT`-typed id to the whole document, for the flows that render
1728
+ * it: the market detail screen (which returns it to the client) and the admin
1729
+ * mutations (activation, soft delete, hard delete with its asset folder).
1730
+ *
1731
+ * Same collections and same visibility rule as
1732
+ * `findEventOrImportedMarketById`; only the projection differs, so anything that
1733
+ * resolves there resolves here too. The caller still decides what its own
1734
+ * audience may see (e.g. `getEvent` runs `canUserViewResourceById`).
1735
+ */
1736
+ declare function findEventOrImportedMarketDetailsById(resourceId: ObjectId | string | null | undefined, options?: EventOrImportedMarketLookupOptions): Promise<EventOrImportedMarketMatch | null>;
1737
+
1738
+ /**
1739
+ * What "the public may still see this resource" means, as a Mongo filter.
1740
+ *
1741
+ * Events, Google imports and AI imports all carry the same `active` +
1742
+ * `deletedAt` pair, so the public lists, the user activity feeds and the
1743
+ * by-id lookup all reuse this one definition instead of restating the pair.
1744
+ */
1745
+ declare const LIVE_RESOURCE_FILTER: {
1746
+ readonly active: true;
1747
+ readonly deletedAt: null;
1748
+ };
1749
+ /**
1750
+ * The JavaScript form of `LIVE_RESOURCE_FILTER`, for rows already loaded.
1751
+ *
1752
+ * A missing `active` counts as inactive: the Mongo filter does not match absent
1753
+ * fields either, so the two forms agree.
1652
1754
  */
1653
- declare function findEventOrImportedMarketById(resourceId: ObjectId | string | null | undefined): Promise<EventOrMarket>;
1755
+ declare function isLiveResource(resource: {
1756
+ active?: boolean | null;
1757
+ deletedAt?: Date | null;
1758
+ }): boolean;
1654
1759
 
1655
1760
  type EventDateSlot = Pick<DateTimeType$1, "startDate" | "startTime">;
1656
1761
  type StartedDateSlot = Pick<DateTimeType$1, "dateStatus" | "startDate" | "startTime">;
@@ -2004,4 +2109,4 @@ declare function hasActiveProLicenceForResource({ includeStripeProtected, userId
2004
2109
  resourceType: EnumResourceType;
2005
2110
  }): Promise<boolean>;
2006
2111
 
2007
- export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, AI_IMPORT_RUN_LOCK_KEY, APP_SETTINGS_ID, type ActiveLicenceOptions, AdBillingCatalogModel, AdBookingModel, AdMetricsModel, AdModel, AdPurchaseModel, AffiliateModel, AiImportRunLockModel, AiImportRunModel, type AiImportRunStatus, type AiImportSiteResult, AiImportedMarketModel, AppSettingModel, type AssociableResourceType, AssociateTypeSchema, AuthHandoffTokenModel, type AuthHandoffTokenType, type AuthTokenClient, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, type DetachedAssociateGrants, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, type IndexBuildFailure, type IndexableModel, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, type ReconcileAssociateGrantsResult, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SCRAPE_SITES_CONFIG_ID, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAiImportRun, type SchemaAiImportedMarket, type SchemaAppSettingsType, type SchemaAssociateType, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventDateArchiveType, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaImpersonationAuditType, type SchemaImpersonationSessionType, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserAssociatedResourcesType, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, ScrapeSiteConfigModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, acceptedAssociateUserIds, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, detachAssociateGrantsForResources, detachStaleAssociateGrants, detachUsersFromResource, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureDatabaseIndexes, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getActiveLicenceForResource, getAssociateAccessMeta, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getUserIdsWithActiveProLicence, getVendorResourceInfo, grantAssociateGrants, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasActiveProLicenceForResource, hasValidLicence, isAssociableResourceType, isProLicence, isProtectedByCurrentStripeSubscription, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, reconcileAssociateGrants, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToCanceled, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
2112
+ export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, AI_IMPORT_RUN_LOCK_KEY, APP_SETTINGS_ID, type ActiveLicenceOptions, AdBillingCatalogModel, AdBookingModel, AdMetricsModel, AdModel, AdPurchaseModel, AffiliateModel, AiImportRunLockModel, AiImportRunModel, type AiImportRunStatus, type AiImportSiteResult, AiImportedMarketModel, type AiImportedMarketReference, AppSettingModel, type AssociableResourceType, AssociateTypeSchema, AuthHandoffTokenModel, type AuthHandoffTokenType, type AuthTokenClient, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, type DetachedAssociateGrants, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, type EventOrImportedMarketLookupOptions, type EventOrImportedMarketMatch, type EventOrImportedMarketReferenceMatch, type EventReference, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, type ImportedMarketReference, type IndexBuildFailure, type IndexableModel, LIVE_RESOURCE_FILTER, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, type ReconcileAssociateGrantsResult, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SCRAPE_SITES_CONFIG_ID, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAiImportRun, type SchemaAiImportedMarket, type SchemaAppSettingsType, type SchemaAssociateType, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventDateArchiveType, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaImpersonationAuditType, type SchemaImpersonationSessionType, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserAssociatedResourcesType, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, ScrapeSiteConfigModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, acceptedAssociateUserIds, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, detachAssociateGrantsForResources, detachStaleAssociateGrants, detachUsersFromResource, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureDatabaseIndexes, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, findEventOrImportedMarketDetailsById, getActiveLicenceForResource, getAssociateAccessMeta, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getUserIdsWithActiveProLicence, getVendorResourceInfo, grantAssociateGrants, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasActiveProLicenceForResource, hasValidLicence, isAssociableResourceType, isLiveResource, isProLicence, isProtectedByCurrentStripeSubscription, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, reconcileAssociateGrants, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToCanceled, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
package/dist/index.mjs CHANGED
@@ -930,7 +930,8 @@ var baseResourceFields = {
930
930
 
931
931
  // src/mongoose/GoogleImportedMarket.ts
932
932
  import {
933
- EnumEventType
933
+ EnumEventType,
934
+ EnumImportedMarketDeactivationReason
934
935
  } from "@timardex/cluemart-shared";
935
936
  import mongoose10 from "mongoose";
936
937
 
@@ -1057,6 +1058,11 @@ var schema7 = new MongooseSchema6(
1057
1058
  type: ResourceImageTypeSchema
1058
1059
  },
1059
1060
  dateTime: [dateTimeSchema],
1061
+ deactivatedReason: {
1062
+ enum: Object.values(EnumImportedMarketDeactivationReason),
1063
+ required: false,
1064
+ type: String
1065
+ },
1060
1066
  deletedAt: { default: null, required: false, type: Date },
1061
1067
  description: { required: true, type: String },
1062
1068
  earliestStartDate: { default: null, required: false, type: Date },
@@ -1111,7 +1117,7 @@ var GoogleImportedMarketModel = mongoose10.models.GoogleImportedMarket || mongoo
1111
1117
  // src/mongoose/AiImportedMarket.ts
1112
1118
  import {
1113
1119
  EnumEventType as EnumEventType2,
1114
- EnumImportedMarketDeactivationReason,
1120
+ EnumImportedMarketDeactivationReason as EnumImportedMarketDeactivationReason2,
1115
1121
  EnumImportedMarketReviewStatus
1116
1122
  } from "@timardex/cluemart-shared";
1117
1123
  import mongoose11 from "mongoose";
@@ -1144,7 +1150,7 @@ var schema8 = new MongooseSchema7(
1144
1150
  },
1145
1151
  dateTime: [dateTimeSchema],
1146
1152
  deactivatedReason: {
1147
- enum: Object.values(EnumImportedMarketDeactivationReason),
1153
+ enum: Object.values(EnumImportedMarketDeactivationReason2),
1148
1154
  required: false,
1149
1155
  type: String
1150
1156
  },
@@ -1982,6 +1988,14 @@ schema15.index({ "licences.licenceType": 1 });
1982
1988
  schema15.index({ promoCodes: 1, active: 1, deletedAt: 1 });
1983
1989
  schema15.index({ email: "text", firstName: "text", lastName: "text" });
1984
1990
  schema15.index({ email: 1 }, { name: "email_unique", unique: true });
1991
+ schema15.index(
1992
+ { email: 1 },
1993
+ {
1994
+ collation: { locale: "en", strength: 2 },
1995
+ name: "email_unique_normalized",
1996
+ unique: true
1997
+ }
1998
+ );
1985
1999
  schema15.index({ "associatedResources.events": 1 });
1986
2000
  schema15.index({ "associatedResources.partners": 1 });
1987
2001
  schema15.index({ "associatedResources.vendors": 1 });
@@ -4374,17 +4388,76 @@ async function updateAllEventDateTimeStatuses() {
4374
4388
  import { updateSingleDateTimeStatus as updateSingleDateTimeStatus2 } from "@timardex/cluemart-shared";
4375
4389
 
4376
4390
  // src/service/event/findEventOrImportedMarketById.ts
4377
- async function findEventOrImportedMarketById(resourceId) {
4378
- if (!resourceId) {
4379
- return null;
4391
+ import { EnumImportedMarketReviewStatus as EnumImportedMarketReviewStatus2 } from "@timardex/cluemart-shared";
4392
+
4393
+ // src/service/event/resourceVisibility.ts
4394
+ var LIVE_RESOURCE_FILTER = { active: true, deletedAt: null };
4395
+ function isLiveResource(resource) {
4396
+ return resource.active === true && resource.deletedAt == null;
4397
+ }
4398
+
4399
+ // src/service/event/findEventOrImportedMarketById.ts
4400
+ var EVENT_REFERENCE_FIELDS = "_id active dateTime deletedAt name owner";
4401
+ var IMPORTED_MARKET_REFERENCE_FIELDS = "_id active dateTime deletedAt name";
4402
+ var AI_IMPORTED_MARKET_REFERENCE_FIELDS = `${IMPORTED_MARKET_REFERENCE_FIELDS} reviewStatus`;
4403
+ function isAddressableAiImport(market, includeDeleted) {
4404
+ const isApproved = market.reviewStatus === EnumImportedMarketReviewStatus2.APPROVED;
4405
+ return includeDeleted ? isApproved || market.deletedAt != null : isApproved && isLiveResource(market);
4406
+ }
4407
+ function pickMatch(eventDoc, googleImportedDoc, aiImportedDoc, includeDeleted) {
4408
+ if (eventDoc && (includeDeleted || isLiveResource(eventDoc))) {
4409
+ return { doc: eventDoc, kind: "event" };
4380
4410
  }
4381
- const normalizedId = convertObjectIdsToStrings(resourceId);
4382
- const [eventDoc, googleImportedDoc, aiImportedDoc] = await Promise.all([
4383
- EventModel.findById(normalizedId).select("_id name dateTime owner").lean().exec(),
4384
- GoogleImportedMarketModel.findById(normalizedId).select("_id name dateTime").lean().exec(),
4385
- AiImportedMarketModel.findById(normalizedId).select("_id name dateTime").lean().exec()
4411
+ if (googleImportedDoc && (includeDeleted || isLiveResource(googleImportedDoc))) {
4412
+ return { doc: googleImportedDoc, kind: "google" };
4413
+ }
4414
+ if (aiImportedDoc && isAddressableAiImport(aiImportedDoc, includeDeleted)) {
4415
+ return { doc: aiImportedDoc, kind: "ai" };
4416
+ }
4417
+ return null;
4418
+ }
4419
+ function normalizeLookupId(resourceId) {
4420
+ return resourceId ? convertObjectIdsToStrings(resourceId) : null;
4421
+ }
4422
+ async function findReferenceRows(normalizedId) {
4423
+ return Promise.all([
4424
+ EventModel.findById(normalizedId).select(EVENT_REFERENCE_FIELDS).lean().exec(),
4425
+ GoogleImportedMarketModel.findById(normalizedId).select(IMPORTED_MARKET_REFERENCE_FIELDS).lean().exec(),
4426
+ AiImportedMarketModel.findById(normalizedId).select(AI_IMPORTED_MARKET_REFERENCE_FIELDS).lean().exec()
4427
+ ]);
4428
+ }
4429
+ async function findDetailRows(normalizedId) {
4430
+ return Promise.all([
4431
+ EventModel.findById(normalizedId).lean().exec(),
4432
+ GoogleImportedMarketModel.findById(normalizedId).lean().exec(),
4433
+ AiImportedMarketModel.findById(normalizedId).lean().exec()
4386
4434
  ]);
4387
- return eventDoc ?? googleImportedDoc ?? aiImportedDoc;
4435
+ }
4436
+ async function findEventOrImportedMarketById(resourceId, options = {}) {
4437
+ const normalizedId = normalizeLookupId(resourceId);
4438
+ if (!normalizedId) {
4439
+ return null;
4440
+ }
4441
+ const [eventDoc, googleImportedDoc, aiImportedDoc] = await findReferenceRows(normalizedId);
4442
+ return pickMatch(
4443
+ eventDoc,
4444
+ googleImportedDoc,
4445
+ aiImportedDoc,
4446
+ options.includeDeleted ?? false
4447
+ );
4448
+ }
4449
+ async function findEventOrImportedMarketDetailsById(resourceId, options = {}) {
4450
+ const normalizedId = normalizeLookupId(resourceId);
4451
+ if (!normalizedId) {
4452
+ return null;
4453
+ }
4454
+ const [eventDoc, googleImportedDoc, aiImportedDoc] = await findDetailRows(normalizedId);
4455
+ return pickMatch(
4456
+ eventDoc,
4457
+ googleImportedDoc,
4458
+ aiImportedDoc,
4459
+ options.includeDeleted ?? false
4460
+ );
4388
4461
  }
4389
4462
 
4390
4463
  // src/service/relations.ts
@@ -5672,6 +5745,7 @@ export {
5672
5745
  GoogleImportedMarketModel,
5673
5746
  ImpersonationAuditModel,
5674
5747
  ImpersonationSessionModel,
5748
+ LIVE_RESOURCE_FILTER,
5675
5749
  LicenceCategory,
5676
5750
  NotificationModel,
5677
5751
  OwnerTypeSchema,
@@ -5725,6 +5799,7 @@ export {
5725
5799
  express,
5726
5800
  findAffiliateByPromoCode,
5727
5801
  findEventOrImportedMarketById,
5802
+ findEventOrImportedMarketDetailsById,
5728
5803
  getActiveLicenceForResource,
5729
5804
  getAssociateAccessMeta,
5730
5805
  getBillingCatalogDefinition,
@@ -5746,6 +5821,7 @@ export {
5746
5821
  hasActiveProLicenceForResource,
5747
5822
  hasValidLicence,
5748
5823
  isAssociableResourceType,
5824
+ isLiveResource,
5749
5825
  isProLicence,
5750
5826
  isProtectedByCurrentStripeSubscription,
5751
5827
  isStandardLicence,