@librechat/data-schemas 0.0.30 → 0.0.31
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.es.js
CHANGED
|
@@ -3561,7 +3561,11 @@ function createTokenMethods(mongoose) {
|
|
|
3561
3561
|
async function updateToken(query, updateData) {
|
|
3562
3562
|
try {
|
|
3563
3563
|
const Token = mongoose.models.Token;
|
|
3564
|
-
|
|
3564
|
+
const dataToUpdate = { ...updateData };
|
|
3565
|
+
if ((updateData === null || updateData === void 0 ? void 0 : updateData.expiresIn) !== undefined) {
|
|
3566
|
+
dataToUpdate.expiresAt = new Date(Date.now() + updateData.expiresIn * 1000);
|
|
3567
|
+
}
|
|
3568
|
+
return await Token.findOneAndUpdate(query, dataToUpdate, { new: true });
|
|
3565
3569
|
}
|
|
3566
3570
|
catch (error) {
|
|
3567
3571
|
logger$1.debug('An error occurred while updating token:', error);
|
|
@@ -3570,6 +3574,7 @@ function createTokenMethods(mongoose) {
|
|
|
3570
3574
|
}
|
|
3571
3575
|
/**
|
|
3572
3576
|
* Deletes all Token documents that match the provided token, user ID, or email.
|
|
3577
|
+
* Email is automatically normalized to lowercase for case-insensitive matching.
|
|
3573
3578
|
*/
|
|
3574
3579
|
async function deleteTokens(query) {
|
|
3575
3580
|
try {
|
|
@@ -3582,7 +3587,7 @@ function createTokenMethods(mongoose) {
|
|
|
3582
3587
|
conditions.push({ token: query.token });
|
|
3583
3588
|
}
|
|
3584
3589
|
if (query.email !== undefined) {
|
|
3585
|
-
conditions.push({ email: query.email });
|
|
3590
|
+
conditions.push({ email: query.email.trim().toLowerCase() });
|
|
3586
3591
|
}
|
|
3587
3592
|
if (query.identifier !== undefined) {
|
|
3588
3593
|
conditions.push({ identifier: query.identifier });
|
|
@@ -3604,6 +3609,7 @@ function createTokenMethods(mongoose) {
|
|
|
3604
3609
|
}
|
|
3605
3610
|
/**
|
|
3606
3611
|
* Finds a Token document that matches the provided query.
|
|
3612
|
+
* Email is automatically normalized to lowercase for case-insensitive matching.
|
|
3607
3613
|
*/
|
|
3608
3614
|
async function findToken(query, options) {
|
|
3609
3615
|
try {
|
|
@@ -3616,7 +3622,7 @@ function createTokenMethods(mongoose) {
|
|
|
3616
3622
|
conditions.push({ token: query.token });
|
|
3617
3623
|
}
|
|
3618
3624
|
if (query.email) {
|
|
3619
|
-
conditions.push({ email: query.email });
|
|
3625
|
+
conditions.push({ email: query.email.trim().toLowerCase() });
|
|
3620
3626
|
}
|
|
3621
3627
|
if (query.identifier) {
|
|
3622
3628
|
conditions.push({ identifier: query.identifier });
|
|
@@ -3683,12 +3689,33 @@ function createRoleMethods(mongoose) {
|
|
|
3683
3689
|
|
|
3684
3690
|
/** Factory function that takes mongoose instance and returns the methods */
|
|
3685
3691
|
function createUserMethods(mongoose) {
|
|
3692
|
+
/**
|
|
3693
|
+
* Normalizes email fields in search criteria to lowercase and trimmed.
|
|
3694
|
+
* Handles both direct email fields and $or arrays containing email conditions.
|
|
3695
|
+
*/
|
|
3696
|
+
function normalizeEmailInCriteria(criteria) {
|
|
3697
|
+
const normalized = { ...criteria };
|
|
3698
|
+
if (typeof normalized.email === 'string') {
|
|
3699
|
+
normalized.email = normalized.email.trim().toLowerCase();
|
|
3700
|
+
}
|
|
3701
|
+
if (Array.isArray(normalized.$or)) {
|
|
3702
|
+
normalized.$or = normalized.$or.map((condition) => {
|
|
3703
|
+
if (typeof condition.email === 'string') {
|
|
3704
|
+
return { ...condition, email: condition.email.trim().toLowerCase() };
|
|
3705
|
+
}
|
|
3706
|
+
return condition;
|
|
3707
|
+
});
|
|
3708
|
+
}
|
|
3709
|
+
return normalized;
|
|
3710
|
+
}
|
|
3686
3711
|
/**
|
|
3687
3712
|
* Search for a single user based on partial data and return matching user document as plain object.
|
|
3713
|
+
* Email fields in searchCriteria are automatically normalized to lowercase for case-insensitive matching.
|
|
3688
3714
|
*/
|
|
3689
3715
|
async function findUser(searchCriteria, fieldsToSelect) {
|
|
3690
3716
|
const User = mongoose.models.User;
|
|
3691
|
-
const
|
|
3717
|
+
const normalizedCriteria = normalizeEmailInCriteria(searchCriteria);
|
|
3718
|
+
const query = User.findOne(normalizedCriteria);
|
|
3692
3719
|
if (fieldsToSelect) {
|
|
3693
3720
|
query.select(fieldsToSelect);
|
|
3694
3721
|
}
|