Socket
Socket
Sign inDemoInstall

v-mate

Package Overview
Dependencies
7
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

77

audit_log.js
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,
};

4

index.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc