@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.cjs +46 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +34 -2
- package/dist/index.d.ts +34 -2
- package/dist/index.mjs +45 -6
- package/dist/index.mjs.map +1 -1
- package/dist/service/index.cjs +45 -5
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +34 -2
- package/dist/service/index.d.ts +34 -2
- package/dist/service/index.mjs +43 -4
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -102,6 +102,7 @@ __export(index_exports, {
|
|
|
102
102
|
didRemoveAnyEventDates: () => didRemoveAnyEventDates,
|
|
103
103
|
didRemoveAnyStartedDates: () => didRemoveAnyStartedDates,
|
|
104
104
|
downgradeVendorProFeatures: () => downgradeVendorProFeatures,
|
|
105
|
+
ensureDatabaseIndexes: () => ensureDatabaseIndexes,
|
|
105
106
|
ensureUserLicenseCompliance: () => ensureUserLicenseCompliance,
|
|
106
107
|
ensureUserLicenseComplianceForUser: () => ensureUserLicenseComplianceForUser,
|
|
107
108
|
eventLicences: () => eventLicences,
|
|
@@ -130,7 +131,7 @@ __export(index_exports, {
|
|
|
130
131
|
locationGeoSchema: () => locationGeoSchema,
|
|
131
132
|
locationsSchema: () => locationsSchema,
|
|
132
133
|
mapVendorLicenceToSubscriptionRewardType: () => mapVendorLicenceToSubscriptionRewardType,
|
|
133
|
-
mongoose: () =>
|
|
134
|
+
mongoose: () => import_mongoose44.default,
|
|
134
135
|
normalizeAffiliatePromoCodes: () => normalizeAffiliatePromoCodes,
|
|
135
136
|
normalizePromoCode: () => normalizePromoCode,
|
|
136
137
|
notifyUsers: () => notifyUsers,
|
|
@@ -3404,12 +3405,47 @@ function normalizeAffiliatePromoCodes(promoCodes) {
|
|
|
3404
3405
|
}
|
|
3405
3406
|
|
|
3406
3407
|
// src/service/database.ts
|
|
3408
|
+
var import_mongoose43 = __toESM(require("mongoose"));
|
|
3409
|
+
|
|
3410
|
+
// src/service/indexes.ts
|
|
3407
3411
|
var import_mongoose42 = __toESM(require("mongoose"));
|
|
3412
|
+
function registeredModels() {
|
|
3413
|
+
return import_mongoose42.default.modelNames().map((modelName) => {
|
|
3414
|
+
const model = import_mongoose42.default.model(modelName);
|
|
3415
|
+
return { createIndexes: () => model.createIndexes(), modelName };
|
|
3416
|
+
});
|
|
3417
|
+
}
|
|
3418
|
+
async function ensureDatabaseIndexes(models = registeredModels()) {
|
|
3419
|
+
const failures = [];
|
|
3420
|
+
await Promise.all(
|
|
3421
|
+
models.map(async ({ createIndexes, modelName }) => {
|
|
3422
|
+
try {
|
|
3423
|
+
await createIndexes();
|
|
3424
|
+
} catch (error) {
|
|
3425
|
+
failures.push({ error, model: modelName });
|
|
3426
|
+
console.error(
|
|
3427
|
+
`[db] Failed to build indexes for ${modelName}: ${error instanceof Error ? error.message : String(error)}`
|
|
3428
|
+
);
|
|
3429
|
+
}
|
|
3430
|
+
})
|
|
3431
|
+
);
|
|
3432
|
+
if (failures.length > 0) {
|
|
3433
|
+
console.error(
|
|
3434
|
+
`[db] ${failures.length} model(s) are missing schema indexes: ${failures.map((failure) => failure.model).join(", ")}`
|
|
3435
|
+
);
|
|
3436
|
+
} else {
|
|
3437
|
+
console.log("[db] Schema indexes verified.");
|
|
3438
|
+
}
|
|
3439
|
+
return failures;
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3442
|
+
// src/service/database.ts
|
|
3408
3443
|
var connectToDatabase = async ({
|
|
3409
3444
|
appName,
|
|
3410
3445
|
dbName,
|
|
3411
3446
|
dbPassword,
|
|
3412
3447
|
dbUser,
|
|
3448
|
+
ensureIndexes = true,
|
|
3413
3449
|
mongodbUri
|
|
3414
3450
|
}) => {
|
|
3415
3451
|
try {
|
|
@@ -3417,11 +3453,14 @@ var connectToDatabase = async ({
|
|
|
3417
3453
|
// Fallback to MongoDB Atlas connection string
|
|
3418
3454
|
`mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
|
|
3419
3455
|
);
|
|
3420
|
-
await
|
|
3456
|
+
await import_mongoose43.default.connect(mongoUri);
|
|
3421
3457
|
const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
|
|
3422
3458
|
console.log(
|
|
3423
3459
|
`${connectionType} connected from server/src/service/database.ts`
|
|
3424
3460
|
);
|
|
3461
|
+
if (ensureIndexes) {
|
|
3462
|
+
void ensureDatabaseIndexes();
|
|
3463
|
+
}
|
|
3425
3464
|
} catch (err) {
|
|
3426
3465
|
console.error("Error connecting to MongoDB:", err);
|
|
3427
3466
|
throw err;
|
|
@@ -3430,7 +3469,7 @@ var connectToDatabase = async ({
|
|
|
3430
3469
|
|
|
3431
3470
|
// src/types/index.ts
|
|
3432
3471
|
var import_express = __toESM(require("express"));
|
|
3433
|
-
var
|
|
3472
|
+
var import_mongoose44 = __toESM(require("mongoose"));
|
|
3434
3473
|
var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
|
|
3435
3474
|
EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
|
|
3436
3475
|
EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
|
|
@@ -3546,15 +3585,15 @@ async function updateAdStatuses() {
|
|
|
3546
3585
|
}
|
|
3547
3586
|
|
|
3548
3587
|
// src/service/objectIdToString.ts
|
|
3549
|
-
var
|
|
3588
|
+
var import_mongoose46 = __toESM(require("mongoose"));
|
|
3550
3589
|
function isValidObjectId(value) {
|
|
3551
|
-
return
|
|
3590
|
+
return import_mongoose46.default.Types.ObjectId.isValid(value);
|
|
3552
3591
|
}
|
|
3553
3592
|
function convertObjectIdsToStrings(obj) {
|
|
3554
3593
|
if (obj === null || obj === void 0) {
|
|
3555
3594
|
return obj;
|
|
3556
3595
|
}
|
|
3557
|
-
if (obj instanceof
|
|
3596
|
+
if (obj instanceof import_mongoose46.default.Types.ObjectId) {
|
|
3558
3597
|
return obj.toString();
|
|
3559
3598
|
}
|
|
3560
3599
|
if (obj instanceof Date) {
|
|
@@ -5233,6 +5272,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5233
5272
|
didRemoveAnyEventDates,
|
|
5234
5273
|
didRemoveAnyStartedDates,
|
|
5235
5274
|
downgradeVendorProFeatures,
|
|
5275
|
+
ensureDatabaseIndexes,
|
|
5236
5276
|
ensureUserLicenseCompliance,
|
|
5237
5277
|
ensureUserLicenseComplianceForUser,
|
|
5238
5278
|
eventLicences,
|