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