mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00

* refactor: move model definitions and database-related methods to packages/data-schemas * ci: update tests due to new DB structure fix: disable mocking `librechat-data-provider` feat: Add schema exports to data-schemas package - Introduced a new schema module that exports various schemas including action, agent, and user schemas. - Updated index.ts to include the new schema exports for better modularity and organization. ci: fix appleStrategy tests fix: Agent.spec.js ci: refactor handleTools tests to use MongoMemoryServer for in-memory database fix: getLogStores imports ci: update banViolation tests to use MongoMemoryServer and improve session mocking test: refactor samlStrategy tests to improve mock configurations and user handling ci: fix crypto mock in handleText tests for improved accuracy ci: refactor spendTokens tests to improve model imports and setup ci: refactor Message model tests to use MongoMemoryServer and improve database interactions * refactor: streamline IMessage interface and move feedback properties to types/message.ts * refactor: use exported initializeRoles from `data-schemas`, remove api workspace version (this serves as an example of future migrations that still need to happen) * refactor: update model imports to use destructuring from `~/db/models` for consistency and clarity * refactor: remove unused mongoose imports from model files for cleaner code * refactor: remove unused mongoose imports from Share, Prompt, and Transaction model files for cleaner code * refactor: remove unused import in Transaction model for cleaner code * ci: update deploy workflow to reference new Docker Dev Branch Images Build and add new workflow for building Docker images on dev branch * chore: cleanup imports
92 lines
2.5 KiB
JavaScript
92 lines
2.5 KiB
JavaScript
const path = require('path');
|
|
const mongoose = require(path.resolve(__dirname, '..', 'api', 'node_modules', 'mongoose'));
|
|
const { User } = require('@librechat/data-schemas').createModels(mongoose);
|
|
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
|
|
const { sendEmail, checkEmailConfig } = require('~/server/utils');
|
|
const { askQuestion, silentExit } = require('./helpers');
|
|
const { createInvite } = require('~/models/inviteUser');
|
|
const connect = require('./connect');
|
|
|
|
(async () => {
|
|
await connect();
|
|
|
|
console.purple('--------------------------');
|
|
console.purple('Invite a new user account!');
|
|
console.purple('--------------------------');
|
|
|
|
if (process.argv.length < 5) {
|
|
console.orange('Usage: npm run invite-user <email>');
|
|
console.orange('Note: if you do not pass in the arguments, you will be prompted for them.');
|
|
console.purple('--------------------------');
|
|
}
|
|
|
|
// Check if email service is enabled
|
|
if (!checkEmailConfig()) {
|
|
console.red('Error: Email service is not enabled!');
|
|
silentExit(1);
|
|
}
|
|
|
|
// Get the email of the user to be invited
|
|
let email = '';
|
|
if (process.argv.length >= 3) {
|
|
email = process.argv[2];
|
|
}
|
|
if (!email) {
|
|
email = await askQuestion('Email:');
|
|
}
|
|
// Validate the email
|
|
if (!email.includes('@')) {
|
|
console.red('Error: Invalid email address!');
|
|
silentExit(1);
|
|
}
|
|
|
|
// Check if the user already exists
|
|
const userExists = await User.findOne({ email });
|
|
if (userExists) {
|
|
console.red('Error: A user with that email already exists!');
|
|
silentExit(1);
|
|
}
|
|
|
|
const token = await createInvite(email);
|
|
const inviteLink = `${process.env.DOMAIN_CLIENT}/register?token=${token}`;
|
|
|
|
const appName = process.env.APP_TITLE || 'LibreChat';
|
|
|
|
if (!checkEmailConfig()) {
|
|
console.green('Send this link to the user:', inviteLink);
|
|
silentExit(0);
|
|
}
|
|
|
|
try {
|
|
await sendEmail({
|
|
email: email,
|
|
subject: `Invite to join ${appName}!`,
|
|
payload: {
|
|
appName: appName,
|
|
inviteLink: inviteLink,
|
|
year: new Date().getFullYear(),
|
|
},
|
|
template: 'inviteUser.handlebars',
|
|
});
|
|
} catch (error) {
|
|
console.error('Error: ' + error.message);
|
|
silentExit(1);
|
|
}
|
|
|
|
// Done!
|
|
console.green('Invitation sent successfully!');
|
|
silentExit(0);
|
|
})();
|
|
|
|
process.on('uncaughtException', (err) => {
|
|
if (!err.message.includes('fetch failed')) {
|
|
console.error('There was an uncaught error:');
|
|
console.error(err);
|
|
}
|
|
|
|
if (err.message.includes('fetch failed')) {
|
|
return;
|
|
} else {
|
|
process.exit(1);
|
|
}
|
|
});
|