v-mate
Advanced tools
Comparing version 1.0.2 to 1.0.3
const lodash = require("lodash"); | ||
async function audit(params, next, prisma, tablesToAudit) { | ||
let { action } = params; | ||
const model = lodash.camelCase(params.model); | ||
let json = null; | ||
let clientIP = null; | ||
let userId = null; | ||
if (params && params.args && params.args.context) { | ||
clientIP = params.args.context.clientIP; | ||
if (params.args.context.tokenDetails) { | ||
userId = params.args.context.tokenDetails.userId; | ||
} | ||
delete params.args.context; | ||
} | ||
if (params && params.args && params.args.data) { | ||
json = params.args.data; | ||
} | ||
let previousDocument = null; | ||
if (process.env.AuditLog) { | ||
if (action === "update") { | ||
let whereCondition = undefined; | ||
if (params && params.args && params.args.where) { | ||
whereCondition = params.args.where; | ||
} | ||
previousDocument = await prisma[model].findFirst({ | ||
where: whereCondition, | ||
}); | ||
} | ||
} | ||
const result = await next(params); | ||
if (process.env.AuditLog) { | ||
if (action === "create" && result) { | ||
await createAuditLog({ | ||
prismaClient: prisma, | ||
tablesToAudit, | ||
Table: params.model, | ||
itemId: result.id, | ||
json, | ||
action, | ||
clientIP, | ||
userId, | ||
}); | ||
} else if (action === "delete" && result) { | ||
await createAuditLog({ | ||
prismaClient: prisma, | ||
tablesToAudit, | ||
Table: params.model, | ||
itemId: result.id, | ||
json: { IsDeleted: true }, | ||
action, | ||
clientIP, | ||
userId, | ||
}); | ||
} else if (action === "update" && previousDocument && result) { | ||
let _action = action; | ||
if (json.IsDeleted) { | ||
_action = "delete"; | ||
} | ||
await createAuditLog({ | ||
prismaClient: prisma, | ||
tablesToAudit, | ||
Table: params.model, | ||
itemId: result.id, | ||
json, | ||
action: _action, | ||
previousDocument, | ||
clientIP, | ||
userId, | ||
}); | ||
} | ||
} | ||
return result; | ||
} | ||
async function createAuditLog({ | ||
@@ -76,3 +151,3 @@ prismaClient, | ||
module.exports = { | ||
createAuditLog, | ||
audit, | ||
}; |
@@ -16,3 +16,3 @@ const { DateTimeResolver } = require("graphql-scalars"); | ||
} = require("./ui_module_component"); | ||
const { createAuditLog } = require("./audit_log"); | ||
const { audit } = require("./audit_log"); | ||
@@ -49,3 +49,3 @@ const Error = objectType({ | ||
...dataAccess, | ||
createAuditLog, | ||
audit, | ||
checkAccess, | ||
@@ -52,0 +52,0 @@ setRoleApiAccess, |
{ | ||
"name": "v-mate", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "API Helper Mate", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
39763
1525
4