Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

audit-trail

tm30tech11ISC1.0.1

This is the official Javascript package for audit trail for TM30 global

audit, trail, audit, trail, tm30

readme

audit-trail

audit-trail - Activity Saving library for (Node.js)

Installation

"dependencies": {
  "audit-trail": "~1.0.1" // see the "releases" section
}

npm install audit-trail

Requirements

  • set the audit index to be created in elasticsearch.
    AUDIT_INDEX=audit-index
  • Set elasticsearch credentials
    ELASTICSEARCH_HOST=localhost
    ELASTICSEARCH_PORT=9200
    ELASTICSEARCH_SCHEME=http
    ELASTICSEARCH_USER=
    ELASTICSEARCH_PASS=
    or
    ELASTICSEARCH_URL=https://user:password@localhost:9200

    Initialization

    const audit = require('audit-trail');

Basic functionality

  • To Save a trail
    audit.trail("An Activity Occurred", "Activityy", {
      data: "Any Other data"
    })
    .then(res => console.log(res))
    .catch(err => console.log(err));
    or `javascript

const res = audit.trail("An Activity Occurred", "Activityy", { data: "Any Other data" }); console.log(res); ///res: {"body":{"index":"audit-index","type":"doc","id":"24af1b40-e50a-11e9-bf2a-9b8edcf022d8","version":1,"result":"created","shards":{"total":2,"successful":2,"failed":0},"seqno":6,"primaryterm":1},"statusCode":201,"headers":{"location":"/audit-index/doc/24af1b40-e50a-11e9-bf2a-9b8edcf022d8","content-type":"application/json; charset=UTF-8","content-length":"194"},"warnings":null,"meta":{"context":null,"request":{"params":{"method":"POST","path":"/audit-index/doc/24af1b40-e50a-11e9-bf2a-9b8edcf022d8","body":"{"service":"vas-audits","message":"An Activity Occurred","action":"Activity","userId":"","timestamp":"2019-10-02T12:45:33.939Z"}","querystring":"","headers":{"User-Agent":"elasticsearch-js/7.3.0 (darwin 18.7.0-x64; Node.js v12.10.0)","Content-Type":"application/json","Content-Length":"128"},"timeout":30000},"options":{"warnings":null},"id":2},"name":"elasticsearch-js","connection":{"url":"http://localhost:9200/","id":"http://localhost:9200/","headers":{},"deadCount":0,"resurrectTimeout":0,"_openRequests":0,"status":"alive","roles":{"master":true,"data":true,"ingest":true,"ml":false}},"attempts":0,"aborted":false}}


-- To get a trail (Using the predefined fetch method)
```javascript
audit.fetch({
    email: "user@user.com",
})
.then(result => {
    console.log(result);
    ///Result: {"total":7,"data":[{"id":"24af1b40-e50a-11e9-bf2a-9b8edcf022d8","service":"vas-audits","message":"An Activity Occurred","action":"Activity","userId":"","timestamp":"2019-10-02T12:45:33.939Z"}]}
})

-- To get a trail using custom elasticsearch query

const query = {
            "query": {"bool": {}},
            "from": 0,
            "size": "10",
            "sort": [{"timestamp": {"order": "desc", "unmapped_type": "date"}}]
};
audit.customQuery(query)
.then(result => {
    console.log(result);
    ///Result: {"total":7,"data":[{"id":"24af1b40-e50a-11e9-bf2a-9b8edcf022d8","service":"vas-audits","message":"An Activity Occurred","action":"Activity","userId":"","timestamp":"2019-10-02T12:45:33.939Z"}]}
})

Tests

Cli

npm install
npm test

Contributors