mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 02:57:34 +00:00
chore: refactor config and fix audits (#406)
This commit is contained in:
+31
-24
@@ -1,14 +1,14 @@
|
||||
import {Link, Store} from '../store/model';
|
||||
import {Logger, Print} from '../logger';
|
||||
import {Config} from '../config';
|
||||
import {Print, logger} from '../logger';
|
||||
import Mail from 'nodemailer/lib/mailer';
|
||||
import {config} from '../config';
|
||||
import nodemailer from 'nodemailer';
|
||||
|
||||
if (Config.notifications.phone.number && !Config.notifications.email.username) {
|
||||
Logger.warn('✖ in order to recieve sms alerts, email notifications must also be configured');
|
||||
if (config.notifications.phone.number && !config.notifications.email.username) {
|
||||
logger.warn('✖ in order to recieve sms alerts, email notifications must also be configured');
|
||||
}
|
||||
|
||||
const [email, phone] = [Config.notifications.email, Config.notifications.phone];
|
||||
const [email, phone] = [config.notifications.email, config.notifications.phone];
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
auth: {
|
||||
@@ -19,26 +19,33 @@ const transporter = nodemailer.createTransport({
|
||||
});
|
||||
|
||||
export function sendSMS(link: Link, store: Store) {
|
||||
const mailOptions: Mail.Options = {
|
||||
attachments: link.screenshot ? [
|
||||
{
|
||||
filename: link.screenshot,
|
||||
path: `./${link.screenshot}`
|
||||
}
|
||||
] : undefined,
|
||||
from: email.username,
|
||||
subject: Print.inStock(link, store, false, true),
|
||||
text: link.cartUrl ? link.cartUrl : link.url,
|
||||
to: generateAddress()
|
||||
};
|
||||
if (phone.number) {
|
||||
logger.debug('↗ sending sms');
|
||||
const carrier = phone.carrier;
|
||||
|
||||
transporter.sendMail(mailOptions, error => {
|
||||
if (error) {
|
||||
Logger.error('✖ couldn\'t send sms', error);
|
||||
} else {
|
||||
Logger.info('✔ sms sent');
|
||||
if (carrier && phone.availableCarriers.has(carrier)) {
|
||||
const mailOptions: Mail.Options = {
|
||||
attachments: link.screenshot ? [
|
||||
{
|
||||
filename: link.screenshot,
|
||||
path: `./${link.screenshot}`
|
||||
}
|
||||
] : undefined,
|
||||
from: email.username,
|
||||
subject: Print.inStock(link, store, false, true),
|
||||
text: link.cartUrl ? link.cartUrl : link.url,
|
||||
to: generateAddress()
|
||||
};
|
||||
|
||||
transporter.sendMail(mailOptions, error => {
|
||||
if (error) {
|
||||
logger.error('✖ couldn\'t send sms', error);
|
||||
} else {
|
||||
logger.info('✔ sms sent');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function generateAddress() {
|
||||
@@ -48,5 +55,5 @@ function generateAddress() {
|
||||
return [phone.number, phone.availableCarriers.get(carrier)].join('@');
|
||||
}
|
||||
|
||||
Logger.error('✖ unknown carrier', carrier);
|
||||
logger.error('✖ unknown carrier', carrier);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user