@timardex/cluemart-server-shared 4.0.6 → 4.0.8

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
@@ -3335,12 +3335,47 @@ function normalizeAffiliatePromoCodes(promoCodes) {
3335
3335
  }
3336
3336
 
3337
3337
  // src/service/database.ts
3338
+ import mongoose40 from "mongoose";
3339
+
3340
+ // src/service/indexes.ts
3338
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
3339
3373
  var connectToDatabase = async ({
3340
3374
  appName,
3341
3375
  dbName,
3342
3376
  dbPassword,
3343
3377
  dbUser,
3378
+ ensureIndexes = true,
3344
3379
  mongodbUri
3345
3380
  }) => {
3346
3381
  try {
@@ -3348,11 +3383,14 @@ var connectToDatabase = async ({
3348
3383
  // Fallback to MongoDB Atlas connection string
3349
3384
  `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
3350
3385
  );
3351
- await mongoose39.connect(mongoUri);
3386
+ await mongoose40.connect(mongoUri);
3352
3387
  const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
3353
3388
  console.log(
3354
3389
  `${connectionType} connected from server/src/service/database.ts`
3355
3390
  );
3391
+ if (ensureIndexes) {
3392
+ void ensureDatabaseIndexes();
3393
+ }
3356
3394
  } catch (err) {
3357
3395
  console.error("Error connecting to MongoDB:", err);
3358
3396
  throw err;
@@ -3361,7 +3399,7 @@ var connectToDatabase = async ({
3361
3399
 
3362
3400
  // src/types/index.ts
3363
3401
  import express from "express";
3364
- import mongoose40 from "mongoose";
3402
+ import mongoose41 from "mongoose";
3365
3403
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
3366
3404
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
3367
3405
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
@@ -3483,15 +3521,15 @@ async function updateAdStatuses() {
3483
3521
  }
3484
3522
 
3485
3523
  // src/service/objectIdToString.ts
3486
- import mongoose41 from "mongoose";
3524
+ import mongoose42 from "mongoose";
3487
3525
  function isValidObjectId(value) {
3488
- return mongoose41.Types.ObjectId.isValid(value);
3526
+ return mongoose42.Types.ObjectId.isValid(value);
3489
3527
  }
3490
3528
  function convertObjectIdsToStrings(obj) {
3491
3529
  if (obj === null || obj === void 0) {
3492
3530
  return obj;
3493
3531
  }
3494
- if (obj instanceof mongoose41.Types.ObjectId) {
3532
+ if (obj instanceof mongoose42.Types.ObjectId) {
3495
3533
  return obj.toString();
3496
3534
  }
3497
3535
  if (obj instanceof Date) {
@@ -5200,6 +5238,7 @@ export {
5200
5238
  didRemoveAnyEventDates,
5201
5239
  didRemoveAnyStartedDates,
5202
5240
  downgradeVendorProFeatures,
5241
+ ensureDatabaseIndexes,
5203
5242
  ensureUserLicenseCompliance,
5204
5243
  ensureUserLicenseComplianceForUser,
5205
5244
  eventLicences,
@@ -5228,7 +5267,7 @@ export {
5228
5267
  locationGeoSchema,
5229
5268
  locationsSchema,
5230
5269
  mapVendorLicenceToSubscriptionRewardType,
5231
- mongoose40 as mongoose,
5270
+ mongoose41 as mongoose,
5232
5271
  normalizeAffiliatePromoCodes,
5233
5272
  normalizePromoCode,
5234
5273
  notifyUsers,