mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
refactor: split api into api, api-cli & api-plugin
This commit is contained in:
@@ -125,12 +125,11 @@ export class SMTP extends VerifiableTransport {
|
||||
* SMTP_SENDER_MAIL: sender of the mail
|
||||
* SMTP_SENDER_NAME: name of the sender
|
||||
* SMTP_SECURE: `true` to enable tls
|
||||
*
|
||||
* @param config SMTP config for instance
|
||||
*/
|
||||
public static getInstance(config?: SMTPConfig): SMTP | undefined {
|
||||
// if an instance of SMTP already exists
|
||||
if (typeof SMTP._instance !== 'undefined') {
|
||||
if (SMTP._instance !== undefined) {
|
||||
return SMTP._instance;
|
||||
}
|
||||
|
||||
@@ -158,7 +157,6 @@ export class SMTP extends VerifiableTransport {
|
||||
*
|
||||
* For more information please consider reading
|
||||
* https://stackoverflow.com/a/2071250
|
||||
*
|
||||
* @param address Address to validate
|
||||
*/
|
||||
public static isValidEmailAddress(address: string): boolean {
|
||||
@@ -170,7 +168,6 @@ export class SMTP extends VerifiableTransport {
|
||||
|
||||
/**
|
||||
* Checks a list of mail addresses for validity
|
||||
*
|
||||
* @param recipients List of recipients to check
|
||||
*/
|
||||
public static isValidRecipientsList(recipients: string[] | undefined): boolean {
|
||||
@@ -181,7 +178,6 @@ export class SMTP extends VerifiableTransport {
|
||||
* Creates an SMTP connection.
|
||||
*
|
||||
* WARNING: This class is supposed to be used as a singleton. You should never call `new SMTP()`
|
||||
*
|
||||
* @param smtpConfig SMTP config
|
||||
*/
|
||||
private constructor(smtpConfig?: SMTPConfig) {
|
||||
@@ -191,13 +187,11 @@ export class SMTP extends VerifiableTransport {
|
||||
password: process.env.SMTP_AUTH_PASSWORD,
|
||||
user: process.env.SMTP_AUTH_USER,
|
||||
},
|
||||
cc: typeof process.env.SMTP_CC === 'undefined' ? [] : (process.env.SMTP_CC as string).split(','),
|
||||
cc: process.env.SMTP_CC === undefined ? [] : (process.env.SMTP_CC as string).split(','),
|
||||
host: process.env.SMTP_HOST,
|
||||
port:
|
||||
typeof process.env.SMTP_PORT === 'undefined' ? undefined : Number.parseInt(process.env.SMTP_PORT, 10),
|
||||
recipients:
|
||||
typeof process.env.SMTP_RECIPIENTS === 'undefined' ? [] : process.env.SMTP_RECIPIENTS.split(','),
|
||||
secure: typeof process.env.SMTP_SECURE === 'undefined' ? false : process.env.SMTP_SECURE === 'true',
|
||||
port: process.env.SMTP_PORT === undefined ? undefined : Number.parseInt(process.env.SMTP_PORT, 10),
|
||||
recipients: process.env.SMTP_RECIPIENTS === undefined ? [] : process.env.SMTP_RECIPIENTS.split(','),
|
||||
secure: process.env.SMTP_SECURE === undefined ? false : process.env.SMTP_SECURE === 'true',
|
||||
sender: {
|
||||
mail: process.env.SMTP_SENDER_MAIL,
|
||||
name: process.env.SMTP_SENDER_NAME,
|
||||
@@ -210,13 +204,13 @@ export class SMTP extends VerifiableTransport {
|
||||
...(deleteUndefinedProperties(environmentConfig) as object),
|
||||
} as SMTPConfig;
|
||||
|
||||
if (typeof config.host === 'undefined') {
|
||||
if (config.host === undefined) {
|
||||
throw new TypeError(
|
||||
'SMTP configuration needs a host. Add it to the config or use environment variables (SMTP_HOST).',
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof config.port === 'undefined' || Number.isNaN(config.port)) {
|
||||
if (config.port === undefined || Number.isNaN(config.port)) {
|
||||
throw new TypeError(
|
||||
'SMTP configuration needs a port. Add it to the config or use environment variables (SMTP_PORT).',
|
||||
);
|
||||
@@ -229,13 +223,13 @@ export class SMTP extends VerifiableTransport {
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof config.auth.user === 'undefined') {
|
||||
if (config.auth.user === undefined) {
|
||||
throw new TypeError(
|
||||
'SMTP auth configuration needs a user. Add it to the config or use environment variables (SMTP_AUTH_USER).',
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof config.auth.password === 'undefined') {
|
||||
if (config.auth.password === undefined) {
|
||||
throw new TypeError(
|
||||
'SMTP auth configuration needs a password.' +
|
||||
'Add it to the config or use environment variables (SMTP_AUTH_PASSWORD).',
|
||||
@@ -248,7 +242,7 @@ export class SMTP extends VerifiableTransport {
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof config.sender.mail === 'undefined') {
|
||||
if (config.sender.mail === undefined) {
|
||||
throw new TypeError(
|
||||
'SMTP configuration needs a sender. Add it to the config or use environment variables (SMTP_SENDER_MAIL).',
|
||||
);
|
||||
@@ -262,7 +256,7 @@ export class SMTP extends VerifiableTransport {
|
||||
throw new Error('Invalid recipients found');
|
||||
}
|
||||
|
||||
if (typeof config.cc === 'undefined') {
|
||||
if (config.cc === undefined) {
|
||||
this.cc = [];
|
||||
} else {
|
||||
if (SMTP.isValidRecipientsList(config.cc)) {
|
||||
@@ -284,7 +278,7 @@ export class SMTP extends VerifiableTransport {
|
||||
},
|
||||
host: config.host,
|
||||
port: config.port,
|
||||
secure: typeof config.secure === 'undefined' ? false : config.secure,
|
||||
secure: config.secure === undefined ? false : config.secure,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -298,7 +292,6 @@ export class SMTP extends VerifiableTransport {
|
||||
/**
|
||||
* Sends a preconfigured mail with recipients and sender configured on
|
||||
* creation of the class (set by environment or on creation of this class)
|
||||
*
|
||||
* @param subject Subject of the mail
|
||||
* @param message message of the mail
|
||||
*/
|
||||
@@ -315,7 +308,6 @@ export class SMTP extends VerifiableTransport {
|
||||
|
||||
/**
|
||||
* Sends a mail object
|
||||
*
|
||||
* @param mail Mail to send
|
||||
*/
|
||||
public async sendMail(mail: MailOptions): Promise<string> {
|
||||
@@ -323,7 +315,7 @@ export class SMTP extends VerifiableTransport {
|
||||
let info = await this.transportAgent.sendMail(mail);
|
||||
|
||||
// it can be undefined (empty response)
|
||||
if (typeof info === 'undefined') {
|
||||
if (info === undefined) {
|
||||
info = 'Successfully sent mail';
|
||||
}
|
||||
|
||||
@@ -337,8 +329,6 @@ export class SMTP extends VerifiableTransport {
|
||||
|
||||
/**
|
||||
* Verify authentication with SMTP server
|
||||
*
|
||||
*
|
||||
* @throws error if you are in a productive environment and don't set ALLOW_NO_TRANSPORT to true
|
||||
* @returns true if the transport is valid
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user