@codefresh-io/audit
Advanced tools
@@ -75,32 +75,39 @@ /* eslint global-require: 0 */ | ||
describe('getAudit', () => { | ||
it('should return correct audit data', async () => { | ||
jest.mock('../../models', () => { | ||
return { | ||
createDatabaseIfNotExists() { | ||
return Promise.resolve(); | ||
}, | ||
getInstance() { | ||
return { | ||
Audit: { | ||
findAndCountAll() { | ||
return Promise.resolve({ | ||
count: 1, | ||
rows: [{ _id: 'testID', action: 'testAction' }], | ||
}); | ||
}, | ||
}, | ||
}; | ||
}, | ||
describe('with range conditions', () => { | ||
it.each([ | ||
{ from: new Date() }, | ||
{ to: new Date() }, | ||
])('should return correct audit data for %o case', async (qs) => { | ||
const expectedResult = { | ||
count: 1, | ||
rows: [{ _id: 'testID', action: 'testAction' }], | ||
}; | ||
}); | ||
const audit = require('../../index'); | ||
await audit.init(); | ||
const result = await audit.getAudit({}); | ||
jest.mock('../../models', () => { | ||
return { | ||
// eslint-disable-next-line no-empty-function | ||
async createDatabaseIfNotExists() {}, | ||
getInstance() { | ||
return { | ||
Audit: { | ||
async findAndCountAll() { | ||
return expectedResult; | ||
}, | ||
}, | ||
}; | ||
}, | ||
}; | ||
}); | ||
expect(result).toEqual({ | ||
rows: [{ _id: 'testID', action: 'testAction' }], | ||
count: 1, | ||
const audit = require('../../index'); | ||
await audit.init(); | ||
const result = await audit.getAudit({ qs, accountId: 'testAccId' }); | ||
expect(result).toEqual({ | ||
rows: [{ _id: 'testID', action: 'testAction' }], | ||
count: 1, | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -107,0 +114,0 @@ |
@@ -72,3 +72,3 @@ /* eslint class-methods-use-this: 0 */ | ||
}); | ||
return data.map(item => item.DISTINCT); | ||
return data.map((item) => item.DISTINCT); | ||
} | ||
@@ -75,0 +75,0 @@ |
@@ -42,3 +42,3 @@ /* eslint class-methods-use-this: 0 */ | ||
if (qs.search) { | ||
if (qs?.search) { | ||
const searchFields = ['req_body', 'req_query', 'req_body', 'req_params', 'req_headers', 'req_url']; | ||
@@ -118,3 +118,2 @@ searchFilters[Op.or] = searchFields.map((sf) => { | ||
module.exports = new AuditQueryBuilder(); |
@@ -0,1 +1,4 @@ | ||
// @ts-check | ||
/** @type {import('pg').PoolConfig} */ | ||
const pgConfig = { | ||
@@ -6,7 +9,7 @@ user: process.env.POSTGRES_USER || 'postgres', | ||
password: process.env.POSTGRES_PASSWORD || 'postgres', | ||
port: process.env.POSTGRES_PORT || 5432, | ||
max: process.env.POSTGRES_MAX_CONNECTIONS || 20, | ||
port: Number.parseInt(process.env.POSTGRES_PORT || '5432', 10), | ||
max: Number.parseInt(process.env.POSTGRES_MAX_CONNECTIONS || '20', 10), | ||
idleTimeoutMillis: 30000, | ||
connectionTimeoutMillis: 20000, | ||
ssl: process.env.POSTGRES_SSL_ENABLE === 'true', | ||
}; | ||
@@ -13,0 +16,0 @@ |
@@ -10,3 +10,2 @@ const fs = require('fs'); | ||
const createDatabaseIfNotExists = async () => { | ||
@@ -64,3 +63,2 @@ const sequelize = new Sequelize('postgres', pgConfig.user, pgConfig.password, { | ||
Object.keys(db) | ||
@@ -77,3 +75,2 @@ .forEach((modelName) => { | ||
module.exports = { | ||
@@ -80,0 +77,0 @@ getInstance, |
{ | ||
"name": "@codefresh-io/audit", | ||
"version": "1.6.6", | ||
"version": "1.7.0", | ||
"description": "Receive and collect audit logs", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib/**/*" | ||
], | ||
"scripts": { | ||
@@ -13,3 +16,4 @@ "start": "node .", | ||
"test:debug": "node --inspect node_modules/.bin/jest --runInBand", | ||
"eslint": "eslint lib/**" | ||
"lint": "eslint lib/**", | ||
"build": "echo 'Nothing to build 🚀' && exit 0" | ||
}, | ||
@@ -26,24 +30,18 @@ "repository": { | ||
"license": "ISC", | ||
"engines": { | ||
"node": "^20 || ^22" | ||
}, | ||
"dependencies": { | ||
"bluebird": "~3.5.2", | ||
"cf-errors": "^0.1.15", | ||
"knex": "2.4.0", | ||
"lodash": "^4.17.21", | ||
"pg": "^8.0.0", | ||
"pg": "^8.14.1", | ||
"sequelize": "6.29.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^4.18.2", | ||
"eslint-config-airbnb": "^17.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-jest": "^21.24.1", | ||
"eslint-plugin-jsx-a11y": "^6.1.1", | ||
"eslint-plugin-react": "^7.11.1", | ||
"jest": "27.0.6", | ||
"randomstring": "^1.1.5", | ||
"supertest": "^3.0.0" | ||
"eslint": "^8.52.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-plugin-import": "^2.29.0", | ||
"eslint-plugin-jest": "^27.4.3", | ||
"jest": "^27.0.6" | ||
}, | ||
"resolutions": { | ||
"js-yaml": "3.13.1" | ||
}, | ||
"jest": { | ||
@@ -66,3 +64,4 @@ "testEnvironment": "node", | ||
} | ||
} | ||
}, | ||
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
} |
4
-33.33%5
-44.44%23739
-87.8%11
-31.25%585
-7.87%