Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Logger.prototype[level.toLowerCase()] = (message) => {
const simple = fmt(level, process.env.SCOPE || 'BOT', message);
if ((Object.keys(levels).indexOf(level) >= Object.keys(levels)
.indexOf(l.logLevel)) && Object.keys(levels).indexOf(level) < 3) {
// eslint-disable-next-line no-console
console.log(simple);
}
if (level.toLowerCase() === 'fatal' && Sentry) {
Sentry.captureMessage(message, {
level: 'fatal',
});
process.exit(4);
}
if (level.toLowerCase() === 'error') {
// eslint-disable-next-line no-console
console.error(simple);
if (typeof message === 'object') {
// eslint-disable-next-line no-console
console.error(message);
}
if (Sentry) {
Sentry.captureException(message);
}
}
};
const path = require('path');
const cors = require('cors');
const fileName = path.basename(__filename, '.js'); // gives the filename without the .js extension
let utils = require('./utils/utils');
let initRedis = require('./utils/initRedis');
const logger = require('sp-json-logger')({fileName: + 'notification-service' + fileName});
let SSE = require('express-sse');
let authUsers = require('./middleware/authUsers');
const Sentry = require('@sentry/node');
var sentryData = process.env.STOCKUP_WEB
Sentry.init({ dsn: sentryData });
// The request handler must be the first middleware on the app
app.use(Sentry.Handlers.requestHandler());
// The error handler must be before any other error middleware
app.use(Sentry.Handlers.errorHandler());
Sentry.captureMessage('Notification Server');
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// let sseMap = {};
let sseUsers = {};
let sseAPI = {};
/**
* Publish will emit message on redis publsher connection
* from where each running notification-service process will pick up the notification and send to client
*/
require('./publisher')(app);
app.get('/:userId/waitForResponse', (req, res) => {
let userId = req.params.userId;
Sentry.withScope((scope) => {
scope.setLevel(level);
each(tags, (value, prop) => {
scope.setTag(prop, String(value));
});
each(extra, (value, prop) => {
scope.setExtra(prop, value || null);
});
if (record.err) {
scope.setExtra('msg', record.msg);
Sentry.captureException(deserializeError(record.err));
} else {
Sentry.captureMessage(record.msg);
}
});
if (error) return errorHandler(error);
});
}
if (!config.has('lastWP') || !config.get('lastWP')) {
const lastWP = await wallpaper.get();
config.set('lastWP', lastWP);
}
updateNotifier({ pkg: manifest, updateCheckInterval: 1000 * 30 }).notify();
if (frun()) {
await clearSettings();
await Unsplash.shared.picOfTheDay();
Sentry.captureMessage('New User', Sentry.Severity.Info);
printBlock(
chalk`Welcome to ${manifest.name}@{dim ${manifest.version}} {bold @${userInfo().username}}`,
'',
chalk`{dim CLI setup {green completed}!}`,
'',
chalk`{bold Enjoy "{yellow ${manifest.name}}" running {green splash}}`,
);
dns.lookup('https://analytics.splash-cli.app/api/users', async (err) => {
if (err) return;
try {
await got('https://analytics.splash-cli.app/api/users', {
method: 'POST',
});
async function captureError(message) {
try {
sentry.captureMessage(message, 'error');
await sentry.flush();
} catch (err) {
/** ignore errors*/
return Promise.resolve();
}
}
Sentry.withScope(scope => {
if (ctx.state) scope.setExtra('state', ctx.state)
if (ctx.input) scope.setExtra('input', ctx.input)
if (error) {
Sentry.captureException(error)
} else {
Sentry.captureMessage(ctx.body)
}
})
}
Sentry.withScope(scope => {
scope.setLevel('info');
scope.setExtra("schema", '"' + deviceInfo.id + '": ' + JSON.stringify(deviceInfo.schemaInfo));
Sentry.captureMessage('Schema ' + deviceInfo.id, 'info');
});
}