refactor: doc and notification (#42)

Signed-off-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
Jef LeCompte
2020-09-18 19:34:09 -04:00
committed by GitHub
parent 643045c7e0
commit fad9ea04c7
6 changed files with 32 additions and 33 deletions
+15 -21
View File
@@ -3,38 +3,32 @@ import {config} from 'dotenv';
config({path: resolve(__dirname, '../.env')});
const email = {
username: process.env.EMAIL_USERNAME,
password: process.env.EMAIL_PASSWORD,
test: process.env.EMAIL_TEST ?? 'false'
};
const notifications = {
email: email.username && email.password
email: {
username: process.env.EMAIL_USERNAME ?? '',
password: process.env.EMAIL_PASSWORD ?? ''
},
slack: {
channel: process.env.SLACK_CHANNEL ?? '',
token: process.env.SLACK_TOKEN ?? ''
},
test: process.env.NOTIFICATION_TEST ?? 'false'
};
const page = {
height: 1920,
navigationTimeout: Number(process.env.PAGE_TIMEOUT) ?? 30000,
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
width: 1080,
navigationTimeout: Number(process.env.PAGE_TIMEOUT) ?? 30000
width: 1080
};
const rateLimitTimeout = Number(process.env.RATE_LIMIT_TIMEOUT) ?? 5000;
const stores = process.env.STORES ?? 'nvidia';
const notificationMethods = process.env.NOTIFICATION_METHODS ?? 'email';
const slack = {
channel: process.env.SLACK_CHANNEL,
token: process.env.SLACK_TOKEN
};
export const Config = {
email,
notifications,
rateLimitTimeout,
page,
rateLimitTimeout: 5000,
stores,
slack,
notificationMethods
stores
};
+2 -2
View File
@@ -8,7 +8,7 @@ import {Logger} from './logger';
/**
* Send test email.
*/
if (Config.email.test === 'true') {
if (Config.notifications.test === 'true') {
sendNotification('test');
}
@@ -25,7 +25,7 @@ async function main() {
await Promise.all(results);
Logger.info('↗ trying stores again');
setTimeout(main, Config.rateLimitTimeout);
setTimeout(main, Config.page.rateLimitTimeout);
}
/**
+2 -2
View File
@@ -3,11 +3,11 @@ import sendEmail from './email';
import sendSlaskMessage from './slack';
export default function sendNotification(cartUrl: string) {
if (Config.notificationMethods.toLocaleLowerCase().includes('email')) {
if (Config.notifications.email.username && Config.notifications.email.password) {
sendEmail(cartUrl);
}
if (Config.notificationMethods.toLocaleLowerCase().includes('slack')) {
if (Config.notifications.slack.channel && Config.notifications.slack.token) {
sendSlaskMessage(cartUrl);
}
}
+2 -2
View File
@@ -2,8 +2,8 @@ import {WebClient} from '@slack/web-api';
import {Config} from '../config';
import {Logger} from '../logger';
const channel = Config.slack.channel ?? '';
const token = Config.slack.token ?? '';
const channel = Config.notifications.slack.channel;
const token = Config.notifications.slack.token;
const web = new WebClient(token);
export default function sendSlackMessage(text: string) {