🔨 Infer typings for config schema (#2656)
* 🚚 Move schema to standalone file * ⚡ Add assertions to string literal arrays * ✨ Infer typings for convict schema * 🔥 Remove unneeded assertions * 🔨 Fix errors surfaced by typings * ⚡ Type nodes.include/exclude per docs * ⚡ Account for types for exception paths * ⚡ Set method alias to flag incorrect paths * ⚡ Replace original with alias * ⚡ Make allowance for nodes.include * ⚡ Adjust leftover calls * 🔀 Fix conflicts * 🔥 Remove unneeded castings * 📘 Simplify exception path type * 📦 Update package-lock.json * 🔥 Remove unneeded imports * 🔥 Remove unrelated file * ⚡ Update schema * ⚡ Update interface * 📦 Update package-lock.json * 📦 Update package-lock.json * 🔥 Remove leftover assertions Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
@@ -24,10 +24,10 @@ export async function getWorkflowOwner(workflowId: string | number): Promise<Use
|
||||
}
|
||||
|
||||
export function isEmailSetUp(): boolean {
|
||||
const smtp = config.get('userManagement.emails.mode') === 'smtp';
|
||||
const host = !!config.get('userManagement.emails.smtp.host');
|
||||
const user = !!config.get('userManagement.emails.smtp.auth.user');
|
||||
const pass = !!config.get('userManagement.emails.smtp.auth.pass');
|
||||
const smtp = config.getEnv('userManagement.emails.mode') === 'smtp';
|
||||
const host = !!config.getEnv('userManagement.emails.smtp.host');
|
||||
const user = !!config.getEnv('userManagement.emails.smtp.auth.user');
|
||||
const pass = !!config.getEnv('userManagement.emails.smtp.auth.pass');
|
||||
|
||||
return smtp && host && user && pass;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ export async function getInstanceOwner(): Promise<User> {
|
||||
* Return the n8n instance base URL without trailing slash.
|
||||
*/
|
||||
export function getInstanceBaseUrl(): string {
|
||||
const n8nBaseUrl = config.get('editorBaseUrl') || getWebhookBaseUrl();
|
||||
const n8nBaseUrl = config.getEnv('editorBaseUrl') || getWebhookBaseUrl();
|
||||
|
||||
return n8nBaseUrl.endsWith('/') ? n8nBaseUrl.slice(0, n8nBaseUrl.length - 1) : n8nBaseUrl;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export function issueJWT(user: User): JwtToken {
|
||||
.digest('hex');
|
||||
}
|
||||
|
||||
const signedToken = jwt.sign(payload, config.get('userManagement.jwtSecret'), {
|
||||
const signedToken = jwt.sign(payload, config.getEnv('userManagement.jwtSecret'), {
|
||||
expiresIn: expiresIn / 1000 /* in seconds */,
|
||||
});
|
||||
|
||||
@@ -57,7 +57,7 @@ export async function resolveJwtContent(jwtPayload: JwtPayload): Promise<User> {
|
||||
}
|
||||
|
||||
export async function resolveJwt(token: string): Promise<User> {
|
||||
const jwtPayload = jwt.verify(token, config.get('userManagement.jwtSecret')) as JwtPayload;
|
||||
const jwtPayload = jwt.verify(token, config.getEnv('userManagement.jwtSecret')) as JwtPayload;
|
||||
return resolveJwtContent(jwtPayload);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,20 +9,20 @@ export class NodeMailer implements UserManagementMailerImplementation {
|
||||
|
||||
constructor() {
|
||||
this.transport = createTransport({
|
||||
host: config.get('userManagement.emails.smtp.host'),
|
||||
port: config.get('userManagement.emails.smtp.port'),
|
||||
secure: config.get('userManagement.emails.smtp.secure'),
|
||||
host: config.getEnv('userManagement.emails.smtp.host'),
|
||||
port: config.getEnv('userManagement.emails.smtp.port'),
|
||||
secure: config.getEnv('userManagement.emails.smtp.secure'),
|
||||
auth: {
|
||||
user: config.get('userManagement.emails.smtp.auth.user'),
|
||||
pass: config.get('userManagement.emails.smtp.auth.pass'),
|
||||
user: config.getEnv('userManagement.emails.smtp.auth.user'),
|
||||
pass: config.getEnv('userManagement.emails.smtp.auth.pass'),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async verifyConnection(): Promise<void> {
|
||||
const host = config.get('userManagement.emails.smtp.host') as string;
|
||||
const user = config.get('userManagement.emails.smtp.auth.user') as string;
|
||||
const pass = config.get('userManagement.emails.smtp.auth.pass') as string;
|
||||
const host = config.getEnv('userManagement.emails.smtp.host');
|
||||
const user = config.getEnv('userManagement.emails.smtp.auth.user');
|
||||
const pass = config.getEnv('userManagement.emails.smtp.auth.pass');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.transport.verify((error: Error) => {
|
||||
@@ -43,8 +43,8 @@ export class NodeMailer implements UserManagementMailerImplementation {
|
||||
}
|
||||
|
||||
async sendMail(mailData: MailData): Promise<SendEmailResult> {
|
||||
let sender = config.get('userManagement.emails.smtp.sender');
|
||||
const user = config.get('userManagement.emails.smtp.auth.user') as string;
|
||||
let sender = config.getEnv('userManagement.emails.smtp.sender');
|
||||
const user = config.getEnv('userManagement.emails.smtp.auth.user');
|
||||
|
||||
if (!sender && user.includes('@')) {
|
||||
sender = user;
|
||||
|
||||
@@ -45,7 +45,7 @@ export class UserManagementMailer {
|
||||
|
||||
constructor() {
|
||||
// Other implementations can be used in the future.
|
||||
if (config.get('userManagement.emails.mode') === 'smtp') {
|
||||
if (config.getEnv('userManagement.emails.mode') === 'smtp') {
|
||||
this.mailer = new NodeMailer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ export function addRoutes(this: N8nApp, ignoredEndpoints: string[], restEndpoint
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
return (req.cookies?.[AUTH_COOKIE_NAME] as string | undefined) ?? null;
|
||||
},
|
||||
secretOrKey: config.get('userManagement.jwtSecret') as string,
|
||||
secretOrKey: config.getEnv('userManagement.jwtSecret'),
|
||||
};
|
||||
|
||||
passport.use(
|
||||
|
||||
@@ -23,7 +23,7 @@ export function ownerNamespace(this: N8nApp): void {
|
||||
const { email, firstName, lastName, password } = req.body;
|
||||
const { id: userId } = req.user;
|
||||
|
||||
if (config.get('userManagement.isInstanceOwnerSetUp')) {
|
||||
if (config.getEnv('userManagement.isInstanceOwnerSetUp')) {
|
||||
Logger.debug(
|
||||
'Request to claim instance ownership failed because instance owner already exists',
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ export function passwordResetNamespace(this: N8nApp): void {
|
||||
this.app.post(
|
||||
`/${this.restEndpoint}/forgot-password`,
|
||||
ResponseHelper.send(async (req: PasswordResetRequest.Email) => {
|
||||
if (config.get('userManagement.emails.mode') === '') {
|
||||
if (config.getEnv('userManagement.emails.mode') === '') {
|
||||
Logger.debug('Request to send password reset email failed because emailing was not set up');
|
||||
throw new ResponseHelper.ResponseError(
|
||||
'Email sending must be set up in order to request a password reset email',
|
||||
|
||||
@@ -31,7 +31,7 @@ export function usersNamespace(this: N8nApp): void {
|
||||
this.app.post(
|
||||
`/${this.restEndpoint}/users`,
|
||||
ResponseHelper.send(async (req: UserRequest.Invite) => {
|
||||
if (config.get('userManagement.emails.mode') === '') {
|
||||
if (config.getEnv('userManagement.emails.mode') === '') {
|
||||
Logger.debug(
|
||||
'Request to send email invite(s) to user(s) failed because emailing was not set up',
|
||||
);
|
||||
@@ -56,14 +56,14 @@ export function usersNamespace(this: N8nApp): void {
|
||||
}
|
||||
|
||||
// TODO: this should be checked in the middleware rather than here
|
||||
if (config.get('userManagement.disabled')) {
|
||||
if (config.getEnv('userManagement.disabled')) {
|
||||
Logger.debug(
|
||||
'Request to send email invite(s) to user(s) failed because user management is disabled',
|
||||
);
|
||||
throw new ResponseHelper.ResponseError('User management is disabled');
|
||||
}
|
||||
|
||||
if (!config.get('userManagement.isInstanceOwnerSetUp')) {
|
||||
if (!config.getEnv('userManagement.isInstanceOwnerSetUp')) {
|
||||
Logger.debug(
|
||||
'Request to send email invite(s) to user(s) failed because the owner account is not set up',
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user