@timardex/cluemart-server-shared 4.0.5 → 4.0.7

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
@@ -1188,15 +1188,47 @@ declare function getSubscriptionRewardPeriodBounds(now?: Date): {
1188
1188
  /**
1189
1189
  * Connect to MongoDB using Mongoose.
1190
1190
  * Supports both local MongoDB (via MONGODB_URI) and MongoDB Atlas (via individual env vars).
1191
+ *
1192
+ * Unless `ensureIndexes` is false, every index declared on the registered
1193
+ * schemas is (re)built in the background after connecting — see
1194
+ * {@link ensureDatabaseIndexes} for why the implicit Mongoose build is not
1195
+ * enough. It is not awaited so a large first build cannot delay startup.
1191
1196
  */
1192
- declare const connectToDatabase: ({ appName, dbName, dbPassword, dbUser, mongodbUri, }: {
1197
+ declare const connectToDatabase: ({ appName, dbName, dbPassword, dbUser, ensureIndexes, mongodbUri, }: {
1193
1198
  appName: string;
1194
1199
  dbName: string;
1195
1200
  dbPassword: string;
1196
1201
  dbUser: string;
1202
+ ensureIndexes?: boolean;
1197
1203
  mongodbUri: string;
1198
1204
  }) => Promise<void>;
1199
1205
 
1206
+ /** Minimal model surface needed to build indexes (kept structural for tests). */
1207
+ interface IndexableModel {
1208
+ createIndexes: () => Promise<unknown>;
1209
+ modelName: string;
1210
+ }
1211
+ interface IndexBuildFailure {
1212
+ error: unknown;
1213
+ model: string;
1214
+ }
1215
+ /**
1216
+ * Builds every index declared on the registered schemas.
1217
+ *
1218
+ * Mongoose only builds them implicitly at connect time, where a failed build is
1219
+ * reported through a background event nobody listens to. A collection that
1220
+ * predates an index — or whose build failed once — then silently keeps
1221
+ * rejecting `$text` queries with "text index required for $text query", which
1222
+ * is exactly how `eventsSearch` loses every result. Running the same builds
1223
+ * explicitly repairs such a collection on the next boot and turns a failure
1224
+ * into a log line naming the model.
1225
+ *
1226
+ * Additive only: `createIndexes` never drops an existing index, so indexes
1227
+ * created outside the schemas are left alone. Failures are collected instead of
1228
+ * thrown so one broken collection cannot stop the application from starting.
1229
+ */
1230
+ declare function ensureDatabaseIndexes(models?: IndexableModel[]): Promise<IndexBuildFailure[]>;
1231
+
1200
1232
  /** Matches partial unique indexes for promo/affiliate codes on active documents. */
1201
1233
  declare const ACTIVE_NOT_DELETED_FILTER: {
1202
1234
  readonly active: true;
@@ -1688,4 +1720,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
1688
1720
  resourceType: EnumResourceType;
1689
1721
  }): Promise<void>;
1690
1722
 
1691
- export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, AI_IMPORT_RUN_LOCK_KEY, APP_SETTINGS_ID, AdBillingCatalogModel, AdBookingModel, AdMetricsModel, AdModel, AdPurchaseModel, AffiliateModel, AiImportRunLockModel, AiImportRunModel, type AiImportRunStatus, type AiImportSiteResult, AiImportedMarketModel, AppSettingModel, AuthHandoffTokenModel, type AuthHandoffTokenType, type AuthTokenClient, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SCRAPE_SITES_CONFIG_ID, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAiImportRun, type SchemaAiImportedMarket, type SchemaAppSettingsType, 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 SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, ScrapeSiteConfigModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToCanceled, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
1723
+ export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, AI_IMPORT_RUN_LOCK_KEY, APP_SETTINGS_ID, AdBillingCatalogModel, AdBookingModel, AdMetricsModel, AdModel, AdPurchaseModel, AffiliateModel, AiImportRunLockModel, AiImportRunModel, type AiImportRunStatus, type AiImportSiteResult, AiImportedMarketModel, AppSettingModel, AuthHandoffTokenModel, type AuthHandoffTokenType, type AuthTokenClient, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, 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, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SCRAPE_SITES_CONFIG_ID, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAiImportRun, type SchemaAiImportedMarket, type SchemaAppSettingsType, 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 SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, ScrapeSiteConfigModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureDatabaseIndexes, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, 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
@@ -1188,15 +1188,47 @@ declare function getSubscriptionRewardPeriodBounds(now?: Date): {
1188
1188
  /**
1189
1189
  * Connect to MongoDB using Mongoose.
1190
1190
  * Supports both local MongoDB (via MONGODB_URI) and MongoDB Atlas (via individual env vars).
1191
+ *
1192
+ * Unless `ensureIndexes` is false, every index declared on the registered
1193
+ * schemas is (re)built in the background after connecting — see
1194
+ * {@link ensureDatabaseIndexes} for why the implicit Mongoose build is not
1195
+ * enough. It is not awaited so a large first build cannot delay startup.
1191
1196
  */
1192
- declare const connectToDatabase: ({ appName, dbName, dbPassword, dbUser, mongodbUri, }: {
1197
+ declare const connectToDatabase: ({ appName, dbName, dbPassword, dbUser, ensureIndexes, mongodbUri, }: {
1193
1198
  appName: string;
1194
1199
  dbName: string;
1195
1200
  dbPassword: string;
1196
1201
  dbUser: string;
1202
+ ensureIndexes?: boolean;
1197
1203
  mongodbUri: string;
1198
1204
  }) => Promise<void>;
1199
1205
 
1206
+ /** Minimal model surface needed to build indexes (kept structural for tests). */
1207
+ interface IndexableModel {
1208
+ createIndexes: () => Promise<unknown>;
1209
+ modelName: string;
1210
+ }
1211
+ interface IndexBuildFailure {
1212
+ error: unknown;
1213
+ model: string;
1214
+ }
1215
+ /**
1216
+ * Builds every index declared on the registered schemas.
1217
+ *
1218
+ * Mongoose only builds them implicitly at connect time, where a failed build is
1219
+ * reported through a background event nobody listens to. A collection that
1220
+ * predates an index — or whose build failed once — then silently keeps
1221
+ * rejecting `$text` queries with "text index required for $text query", which
1222
+ * is exactly how `eventsSearch` loses every result. Running the same builds
1223
+ * explicitly repairs such a collection on the next boot and turns a failure
1224
+ * into a log line naming the model.
1225
+ *
1226
+ * Additive only: `createIndexes` never drops an existing index, so indexes
1227
+ * created outside the schemas are left alone. Failures are collected instead of
1228
+ * thrown so one broken collection cannot stop the application from starting.
1229
+ */
1230
+ declare function ensureDatabaseIndexes(models?: IndexableModel[]): Promise<IndexBuildFailure[]>;
1231
+
1200
1232
  /** Matches partial unique indexes for promo/affiliate codes on active documents. */
1201
1233
  declare const ACTIVE_NOT_DELETED_FILTER: {
1202
1234
  readonly active: true;
@@ -1688,4 +1720,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
1688
1720
  resourceType: EnumResourceType;
1689
1721
  }): Promise<void>;
1690
1722
 
1691
- export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, AI_IMPORT_RUN_LOCK_KEY, APP_SETTINGS_ID, AdBillingCatalogModel, AdBookingModel, AdMetricsModel, AdModel, AdPurchaseModel, AffiliateModel, AiImportRunLockModel, AiImportRunModel, type AiImportRunStatus, type AiImportSiteResult, AiImportedMarketModel, AppSettingModel, AuthHandoffTokenModel, type AuthHandoffTokenType, type AuthTokenClient, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, EnumPubSubEvents, EventDateArchiveModel, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, ImpersonationAuditModel, ImpersonationSessionModel, LicenceCategory, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SCRAPE_SITES_CONFIG_ID, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAiImportRun, type SchemaAiImportedMarket, type SchemaAppSettingsType, 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 SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, ScrapeSiteConfigModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, schemaAdresource, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, splitEventDatesForArchive, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToCanceled, upgradeUserToLicence, userLicenseSchema, vendorOwnerHasProLicence, vendorProductTypeSchema };
1723
+ export { ACTIVE_NOT_DELETED_FILTER, AD_BILLING_CATALOG_COLLECTION_NAME, AI_IMPORT_RUN_LOCK_KEY, APP_SETTINGS_ID, AdBillingCatalogModel, AdBookingModel, AdMetricsModel, AdModel, AdPurchaseModel, AffiliateModel, AiImportRunLockModel, AiImportRunModel, type AiImportRunStatus, type AiImportSiteResult, AiImportedMarketModel, AppSettingModel, AuthHandoffTokenModel, type AuthHandoffTokenType, type AuthTokenClient, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, 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, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SCRAPE_SITES_CONFIG_ID, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaAiImportRun, type SchemaAiImportedMarket, type SchemaAppSettingsType, 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 SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, ScrapeSiteConfigModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureDatabaseIndexes, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, 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
@@ -1030,6 +1030,7 @@ var schema7 = new MongooseSchema6(
1030
1030
  required: false,
1031
1031
  type: mongoose10.Schema.Types.ObjectId
1032
1032
  },
1033
+ contactDetails: { required: false, type: ContactDetailsSchema },
1033
1034
  cover: {
1034
1035
  required: false,
1035
1036
  type: ResourceImageTypeSchema
@@ -1115,6 +1116,7 @@ var schema8 = new MongooseSchema7(
1115
1116
  required: false,
1116
1117
  type: mongoose11.Schema.Types.ObjectId
1117
1118
  },
1119
+ contactDetails: { required: false, type: ContactDetailsSchema },
1118
1120
  cover: {
1119
1121
  required: false,
1120
1122
  type: ResourceImageTypeSchema
@@ -3333,12 +3335,47 @@ function normalizeAffiliatePromoCodes(promoCodes) {
3333
3335
  }
3334
3336
 
3335
3337
  // src/service/database.ts
3338
+ import mongoose40 from "mongoose";
3339
+
3340
+ // src/service/indexes.ts
3336
3341
  import mongoose39 from "mongoose";
3342
+ function registeredModels() {
3343
+ return mongoose39.modelNames().map((modelName) => {
3344
+ const model = mongoose39.model(modelName);
3345
+ return { createIndexes: () => model.createIndexes(), modelName };
3346
+ });
3347
+ }
3348
+ async function ensureDatabaseIndexes(models = registeredModels()) {
3349
+ const failures = [];
3350
+ await Promise.all(
3351
+ models.map(async ({ createIndexes, modelName }) => {
3352
+ try {
3353
+ await createIndexes();
3354
+ } catch (error) {
3355
+ failures.push({ error, model: modelName });
3356
+ console.error(
3357
+ `[db] Failed to build indexes for ${modelName}: ${error instanceof Error ? error.message : String(error)}`
3358
+ );
3359
+ }
3360
+ })
3361
+ );
3362
+ if (failures.length > 0) {
3363
+ console.error(
3364
+ `[db] ${failures.length} model(s) are missing schema indexes: ${failures.map((failure) => failure.model).join(", ")}`
3365
+ );
3366
+ } else {
3367
+ console.log("[db] Schema indexes verified.");
3368
+ }
3369
+ return failures;
3370
+ }
3371
+
3372
+ // src/service/database.ts
3337
3373
  var connectToDatabase = async ({
3338
3374
  appName,
3339
3375
  dbName,
3340
3376
  dbPassword,
3341
3377
  dbUser,
3378
+ ensureIndexes = true,
3342
3379
  mongodbUri
3343
3380
  }) => {
3344
3381
  try {
@@ -3346,11 +3383,14 @@ var connectToDatabase = async ({
3346
3383
  // Fallback to MongoDB Atlas connection string
3347
3384
  `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
3348
3385
  );
3349
- await mongoose39.connect(mongoUri);
3386
+ await mongoose40.connect(mongoUri);
3350
3387
  const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
3351
3388
  console.log(
3352
3389
  `${connectionType} connected from server/src/service/database.ts`
3353
3390
  );
3391
+ if (ensureIndexes) {
3392
+ void ensureDatabaseIndexes();
3393
+ }
3354
3394
  } catch (err) {
3355
3395
  console.error("Error connecting to MongoDB:", err);
3356
3396
  throw err;
@@ -3359,7 +3399,7 @@ var connectToDatabase = async ({
3359
3399
 
3360
3400
  // src/types/index.ts
3361
3401
  import express from "express";
3362
- import mongoose40 from "mongoose";
3402
+ import mongoose41 from "mongoose";
3363
3403
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
3364
3404
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
3365
3405
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
@@ -3481,15 +3521,15 @@ async function updateAdStatuses() {
3481
3521
  }
3482
3522
 
3483
3523
  // src/service/objectIdToString.ts
3484
- import mongoose41 from "mongoose";
3524
+ import mongoose42 from "mongoose";
3485
3525
  function isValidObjectId(value) {
3486
- return mongoose41.Types.ObjectId.isValid(value);
3526
+ return mongoose42.Types.ObjectId.isValid(value);
3487
3527
  }
3488
3528
  function convertObjectIdsToStrings(obj) {
3489
3529
  if (obj === null || obj === void 0) {
3490
3530
  return obj;
3491
3531
  }
3492
- if (obj instanceof mongoose41.Types.ObjectId) {
3532
+ if (obj instanceof mongoose42.Types.ObjectId) {
3493
3533
  return obj.toString();
3494
3534
  }
3495
3535
  if (obj instanceof Date) {
@@ -5198,6 +5238,7 @@ export {
5198
5238
  didRemoveAnyEventDates,
5199
5239
  didRemoveAnyStartedDates,
5200
5240
  downgradeVendorProFeatures,
5241
+ ensureDatabaseIndexes,
5201
5242
  ensureUserLicenseCompliance,
5202
5243
  ensureUserLicenseComplianceForUser,
5203
5244
  eventLicences,
@@ -5226,7 +5267,7 @@ export {
5226
5267
  locationGeoSchema,
5227
5268
  locationsSchema,
5228
5269
  mapVendorLicenceToSubscriptionRewardType,
5229
- mongoose40 as mongoose,
5270
+ mongoose41 as mongoose,
5230
5271
  normalizeAffiliatePromoCodes,
5231
5272
  normalizePromoCode,
5232
5273
  notifyUsers,