Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
knex-utils
Advanced tools
Common utilities for knex.js
** Connection init example
const config = require('config');
const { connectionUtils, heartbeatChecker } = require('knex-utils');
const HEARTBEAT_QUERY = heartbeatChecker.HEARTBEAT_QUERIES.POSTGRESQL;
const knexConfig = config.get('db'); //knex-utils directly passes config entity to knex, so see knex documentation for exact format
let _knex;
function getKnexInstance() {
return _knex || _initKnexInstance();
}
function _initKnexInstance() {
_knex = connectionUtils.getKnexInstance(knexConfig, connectionUtils.getRegistry(), logger);
return _knex;
}
/**
*
* @returns {Object} heartbeat check result
*/
function checkHeartBeat() {
return heartbeatChecker.checkHeartbeat(_knex, HEARTBEAT_QUERY);
}
function close() {
if (_knex) {
const promise = _knex.destroy();
_knex = undefined;
connectionUtils.getRegistry().length = 0; //ToDo implement more specific removal of connections from registry
return promise;
}
return Promise.resolve();
}
module.exports = {
getKnexInstance,
checkHeartBeat,
close
};
** Hearbeat usage example
const { heartbeatChecker } = require('knex-utils');
const HEARTBEAT_QUERY = heartbeatChecker.HEARTBEAT_QUERIES.POSTGRESQL;
const knex = require('./db/db.service').getKnexInstance(); //replace with whatever method you use to obtain knex instance
const appPromise = swaggerService.generateSwagger(true) // could be any async startup activity, or you can start the chain with 'db.checkHeartBeat'
.then(async () => {
const dbCheckResult = await heartbeatChecker.checkHeartbeat(knex, HEARTBEAT_QUERY);;
if (dbCheckResult.isOk === false) {
console.error('DB connection error: ', dbCheckResult.error);
throw (dbCheckResult.error);
}
})
.then(async () => {
const app = express();
// <...> complete app initialization omitted
return app;
}
).catch((e) => {
console.error('Error while starting application: ', e);
throw e;
});
function getAppAsync() {
return appPromise;
}
module.exports = {
getAppAsync
};
FAQs
Useful utilities for Knex.js
We found that knex-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.