Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@adminforth/audit-log

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adminforth/audit-log - npm Package Compare versions

Comparing version 1.0.36 to 1.0.37

dist/AuditLogView.vue

29

dist/index.js

@@ -66,4 +66,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

});
/**
* Create a custom action in the audit log resource
* @param resourceId - The resourceId of the resource that the action is being performed on. Can be null if the action is not related to a specific resource.
* @param actionId - The id of the action being performed, can be random string
* @param data - The data to be stored in the audit log
* @param user - The adminUser user performing the action
*/
this.logCustomAction = (resourceId, actionId, data, user) => __awaiter(this, void 0, void 0, function* () {
if (resourceId) {
const resource = this.adminforth.config.resources.find((r) => r.resourceId === resourceId);
if (!resource) {
const similarResource = this.adminforth.config.resources.find((r) => r.resourceId.includes(resourceId));
throw new Error(`Resource ${resourceId} not found. Did you mean ${similarResource.resourceId}?`);
}
}
const record = {
[this.options.resourceColumns.resourceIdColumnName]: resourceId,
[this.options.resourceColumns.resourceActionColumnName]: actionId,
[this.options.resourceColumns.resourceDataColumnName]: { 'oldRecord': {}, 'newRecord': data },
[this.options.resourceColumns.resourceUserIdColumnName]: user.pk,
[this.options.resourceColumns.resourceRecordIdColumnName]: null,
[this.options.resourceColumns.resourceCreatedColumnName]: dayjs.utc().format()
};
const auditLogResource = this.adminforth.config.resources.find((r) => r.resourceId === this.auditLogResource);
yield this.adminforth.createResourceRecord({ resource: auditLogResource, record, adminUser: user });
});
this.options = options;
}
instanceUniqueRepresentation(pluginOptions) {
return `single`;
}
modifyResourceConfig(adminforth, resourceConfig) {

@@ -70,0 +99,0 @@ super.modifyResourceConfig(adminforth, resourceConfig);

37

index.ts

@@ -26,9 +26,13 @@ import type {

instanceUniqueRepresentation(pluginOptions: any) : string {
return `single`;
}
static defaultError = 'Sorry, you do not have access to this resource.'
createLogRecord = async (resource: AdminForthResource, action: AllowedActionsEnum, data: Object, user: AdminUser, oldRecord: Object) => {
createLogRecord = async (resource: AdminForthResource, action: AllowedActionsEnum | string, data: Object, user: AdminUser, oldRecord?: Object) => {
const recordIdFieldName = resource.columns.find((c) => c.primaryKey === true)?.name;
const recordId = data?.[recordIdFieldName] || oldRecord?.[recordIdFieldName];
const connector = this.adminforth.connectors[resource.dataSource];
const newRecord = action == AllowedActionsEnum.delete ? {} : (await connector.getRecordByPrimaryKey(resource, recordId)) || {};

@@ -80,2 +84,31 @@ if (action !== AllowedActionsEnum.delete) {

/**
* Create a custom action in the audit log resource
* @param resourceId - The resourceId of the resource that the action is being performed on. Can be null if the action is not related to a specific resource.
* @param actionId - The id of the action being performed, can be random string
* @param data - The data to be stored in the audit log
* @param user - The adminUser user performing the action
*/
logCustomAction = async (resourceId: string | null, actionId: string, data: Object, user: AdminUser) => {
if (resourceId) {
const resource = this.adminforth.config.resources.find((r) => r.resourceId === resourceId);
if (!resource) {
const similarResource = this.adminforth.config.resources.find((r) => r.resourceId.includes(resourceId));
throw new Error(`Resource ${resourceId} not found. Did you mean ${similarResource.resourceId}?`)
}
}
const record = {
[this.options.resourceColumns.resourceIdColumnName]: resourceId,
[this.options.resourceColumns.resourceActionColumnName]: actionId,
[this.options.resourceColumns.resourceDataColumnName]: { 'oldRecord': {}, 'newRecord': data },
[this.options.resourceColumns.resourceUserIdColumnName]: user.pk,
[this.options.resourceColumns.resourceRecordIdColumnName]: null,
[this.options.resourceColumns.resourceCreatedColumnName]: dayjs.utc().format()
}
const auditLogResource = this.adminforth.config.resources.find((r) => r.resourceId === this.auditLogResource);
await this.adminforth.createResourceRecord({ resource: auditLogResource, record, adminUser: user});
}
modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {

@@ -82,0 +115,0 @@ super.modifyResourceConfig(adminforth, resourceConfig);

7

package.json
{
"name": "@adminforth/audit-log",
"version": "1.0.36",
"version": "1.0.37",
"description": "AdminForth plugin for logging all actions (who did what and when)",

@@ -9,4 +9,5 @@ "main": "dist/index.js",

"scripts": {
"rollout": "tsc && cp -rf custom dist/ && npm version patch && npm publish --access public",
"postinstall": "npm link adminforth"
"rollout": "tsc && rsync -av --exclude 'node_modules' custom/ dist/ && npm version patch && npm publish --access public",
"build": "tsc",
"prepare": "npm link adminforth"
},

@@ -13,0 +14,0 @@ "author": "devforth",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc