Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ESLint with StandardJS #898

Merged
merged 4 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

10 changes: 5 additions & 5 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
require('dotenv').config();
'use strict'
require('dotenv').config()

const testMode = parseInt(process.env.TEST_MODE) === 1;
const isAcceptanceTestTarget = ['local', 'dev', 'development', 'test', 'qa', 'preprod'].includes(process.env.NODE_ENV);
const testMode = parseInt(process.env.TEST_MODE) === 1
const isAcceptanceTestTarget = ['local', 'dev', 'development', 'test', 'qa', 'preprod'].includes(process.env.NODE_ENV)

module.exports = {
version: '1.0',
Expand Down Expand Up @@ -37,4 +37,4 @@ module.exports = {
},

isAcceptanceTestTarget
};
}
100 changes: 50 additions & 50 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
'use strict';
'use strict'

require('dotenv').config();
require('dotenv').config()

const GoodWinston = require('good-winston');
const Hapi = require('@hapi/hapi');
const GoodWinston = require('good-winston')
const Hapi = require('@hapi/hapi')

const config = require('./config');
const db = require('./src/lib/connectors/db');
const { logger } = require('./src/logger');
const goodWinstonStream = new GoodWinston({ winston: logger });
const config = require('./config')
const db = require('./src/lib/connectors/db')
const { logger } = require('./src/logger')
const goodWinstonStream = new GoodWinston({ winston: logger })

const serverPlugins = {
blipp: require('blipp'),
hapiAuthJwt2: require('hapi-auth-jwt2'),
good: require('@hapi/good')
};
}

const server = new Hapi.Server(config.server);
const server = new Hapi.Server(config.server)

function validateJWT (decoded, request, h) {
request.log('debug', `validate JWT at ${request.path} with payload:`);
request.log('debug', request.payload);
request.log('debug', 'decodes as: ');
request.log('debug', decoded);

const isValid = !!decoded.id;
const message = isValid ? 'huzah... JWT OK' : 'boo... JWT failed';
request.log('debug', message);
return { isValid };
request.log('debug', `validate JWT at ${request.path} with payload:`)
request.log('debug', request.payload)
request.log('debug', 'decodes as: ')
request.log('debug', decoded)

const isValid = !!decoded.id
const message = isValid ? 'huzah... JWT OK' : 'boo... JWT failed'
request.log('debug', message)
return { isValid }
}

const initGood = async () => {
Expand All @@ -39,74 +39,74 @@ const initGood = async () => {
winston: [goodWinstonStream]
}
}
});
};
})
}

const initBlipp = async () => {
await server.register({
plugin: serverPlugins.blipp,
options: config.blipp
});
};
})
}

const configureJwtStrategy = () => {
server.auth.strategy('jwt', 'jwt', {
key: process.env.JWT_SECRET, // Never Share your secret key
validate: validateJWT, // validate function defined above
verifyOptions: {}, // pick a strong algorithm
verify: validateJWT
});
})

server.auth.default('jwt');
};
server.auth.default('jwt')
}

async function start () {
try {
await initGood();
await initBlipp();
await initGood()
await initBlipp()

await server.register({ plugin: serverPlugins.hapiAuthJwt2 });
await server.register({ plugin: serverPlugins.hapiAuthJwt2 })

configureJwtStrategy();
configureJwtStrategy()

// load routes
server.route(require('./src/routes/crm'));
server.route(require('./src/v2/routes'));
server.route(require('./src/routes/crm'))
server.route(require('./src/v2/routes'))

if (!module.parent) {
await server.start();
const name = process.env.SERVICE_NAME;
const uri = server.info.uri;
server.log('info', `Service ${name} running at: ${uri}`);
await server.start()
const name = process.env.SERVICE_NAME
const uri = server.info.uri
server.log('info', `Service ${name} running at: ${uri}`)
}
} catch (err) {
logger.error('Failed to start server', err);
logger.error('Failed to start server', err)
}
}

const processError = message => err => {
logger.error(message, err);
process.exit(1);
};
logger.error(message, err)
process.exit(1)
}

process
.on('unhandledRejection', processError('unhandledRejection'))
.on('uncaughtException', processError('uncaughtException'))
.on('SIGINT', async () => {
logger.info('Stopping CRM service');
logger.info('Stopping CRM service')

await server.stop();
logger.info('1/2: Hapi server stopped');
await server.stop()
logger.info('1/2: Hapi server stopped')

await db.pool.end();
logger.info('2/2: Connection pool closed');
await db.pool.end()
logger.info('2/2: Connection pool closed')

return process.exit(0);
});
return process.exit(0)
})

if (!module.parent) {
start();
start()
}

module.exports = server;
module.exports._start = start;
module.exports = server
module.exports._start = start
72 changes: 33 additions & 39 deletions migrations/20171201091402-crm.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
'use strict';
'use strict'

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;
const fs = require('fs')
const path = require('path')
let Promise

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};
exports.setup = function (options, _seedLink) {
Promise = options.Promise
}

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20171201091402-crm-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);
exports.up = function (db) {
const filePath = path.join(__dirname, 'sqls', '20171201091402-crm-up.sql')
return new Promise(function (resolve, reject) {
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) {
if (err) return reject(err)
console.log('received data: ' + data)

resolve(data);
});
resolve(data)
})
})
.then(function(data) {
return db.runSql(data);
});
};
.then(function (data) {
return db.runSql(data)
})
}

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20171201091402-crm-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);
exports.down = function (db) {
const filePath = path.join(__dirname, 'sqls', '20171201091402-crm-down.sql')
return new Promise(function (resolve, reject) {
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) {
if (err) return reject(err)
console.log('received data: ' + data)

resolve(data);
});
resolve(data)
})
})
.then(function(data) {
return db.runSql(data);
});
};
.then(function (data) {
return db.runSql(data)
})
}

exports._meta = {
"version": 1
};
version: 1
}
72 changes: 33 additions & 39 deletions migrations/20171204113320-add-role-documentview.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
'use strict';
'use strict'

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;
const fs = require('fs')
const path = require('path')
let Promise

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};
exports.setup = function (options, _seedLink) {
Promise = options.Promise
}

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20171204113320-add-role-documentview-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);
exports.up = function (db) {
const filePath = path.join(__dirname, 'sqls', '20171204113320-add-role-documentview-up.sql')
return new Promise(function (resolve, reject) {
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) {
if (err) return reject(err)
console.log('received data: ' + data)

resolve(data);
});
resolve(data)
})
})
.then(function(data) {
return db.runSql(data);
});
};
.then(function (data) {
return db.runSql(data)
})
}

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20171204113320-add-role-documentview-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);
exports.down = function (db) {
const filePath = path.join(__dirname, 'sqls', '20171204113320-add-role-documentview-down.sql')
return new Promise(function (resolve, reject) {
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) {
if (err) return reject(err)
console.log('received data: ' + data)

resolve(data);
});
resolve(data)
})
})
.then(function(data) {
return db.runSql(data);
});
};
.then(function (data) {
return db.runSql(data)
})
}

exports._meta = {
"version": 1
};
version: 1
}
Loading