Socket
Book a DemoInstallSign in
Socket

@cme-pro/mongoose-audit

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cme-pro/mongoose-audit

Mongoose plugin to store audit information like userAgent, ip, country, etc...

0.0.2
latest
Source
npmnpm
Version published
Maintainers
2
Created
Source

npm node downloads

mongoose-audit

Mongoose plugin to store audit information like userAgent, ip, country, etc...

This plugin simply adds the following fields:

  • createdBy
  • updatedBy
  • deletedBy
  • createdFrom
  • updatedFrom
  • deletedFrom

Where:

  • createdBy, updatedBy and deletedBy are a user id,
  • createdFrom, updatedFrom and deletedFrom have the following structure:
    • userAgent
    • ip
    • country
    • continent
    • region
    • city
    • zip
    • lat
    • lng
    • tz

Note: deletedBy and deletedFrom are only useful if combined with mongoose-delete plugin.

Installation

$ npm install mongoose-audit --save

Overview

Adding plugin to the schema

BlogPost.plugin(mongooseAudit, { userModel: 'Author' });

Plugin options

  • userModel - optional (default is "User"). The mongoose Model managing users. Used to populate the field).

Usage

On create:

    const post = new BlogPost({});
    post.createdBy = currentUserId;
    post.createdFrom = {{ ip, userAgent, country };
    await post.save();

On update:

    post.set();
    post.updatedBy = currentUserId;
    post.updatedFrom = {{ ip, userAgent, country };
    await post.save();

On delete (only useful if combined with mongoose-delete plugin)

    post.deletedBy = currentUserId;
    post.deletedFrom = {{ ip, userAgent, country };
    await post.save();
    await post.delete();

Keywords

mongoose

FAQs

Package last updated on 08 Mar 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.