# data-tracer

> Event tracer, Logger and more WIP

Latest version **0.2.26** (published 2021-10-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install data-tracer
pnpm add data-tracer
yarn add data-tracer
bun add data-tracer
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.26 |
| Published | 2021-10-05 |
| First published | 2020-02-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | * |
| Dependencies | 5 |
| Unpacked size | 359.5 KB |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ashwin |
| Maintainers | ashwinachu10 |
| Keywords | node, logger, audit |

## Links

- npm: https://www.npmjs.com/package/data-tracer
- Repository: https://github.com/SAshwinAchu10/data-tracer
- Issues: https://github.com/SAshwinAchu10/data-tracer/issues
- npm.io page: https://npm.io/package/data-tracer

## Dependencies (5)

- [async](https://npm.io/package/async.md) ^0.1.22
- [typeorm](https://npm.io/package/typeorm.md) ^0.2.22
- [mongoose](https://npm.io/package/mongoose.md) ^5.9.1
- [@types/node](https://npm.io/package/@types/node.md) ^13.7.2
- [@sendgrid/mail](https://npm.io/package/@sendgrid/mail.md) ^6.5.2

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads

## Recent versions

- 0.2.26 (latest) — 2021-10-05
- 0.2.25 — 2020-09-23
- 0.2.24 — 2020-03-12
- 0.2.23 — 2020-03-12
- 0.2.22 — 2020-03-11
- 0.2.21 — 2020-03-09
- 0.2.20 — 2020-03-09
- 0.2.19 — 2020-03-09
- 0.2.18 — 2020-03-09
- 0.2.17 — 2020-03-05
- 0.2.16 — 2020-03-05
- 0.2.15 — 2020-03-05
- 0.2.14 — 2020-03-05
- 0.2.13 — 2020-03-05
- 0.2.12 — 2020-02-21
- … 38 more at https://npm.io/package/data-tracer/versions

## README

# Data Tracer

[![N|Solid](https://video.oznoz.com/media/brands/property_logo/1421940829_S1_AlienMonkeys_logo.png)]()


#### Installation

```javascript
$ npm i data-tracer
```


##### Import 
```javascript
import { Audit, DataTracer } from 'data-tracer';
```


##### Instantiate Tracer

#### Mongoose
```javascript
Audit.addTracer('mongoose', { connectionString: 'mongodb://localhost:27017/db', appName: 'Apple-Rest' });
```


#### Mongo Aggregation Query
```javascript
import { Audit } from 'data-tracer';


app.get('/audits', async (req: any, res: any) => {
      let query: any = req.query;
      if (query['page'] == undefined) query['page'] = 1;
      if (query['limit'] == undefined) query['limit'] = 10;
      let q: any =
        query['q'] == undefined
          ? [{}]
          : [
            { when: { $regex: `${query['q']}`, $options: 'i' } },
            { what: { $regex: `${query['q']}`, $options: 'i' } },
            { type: { $regex: `${query['q']}`, $options: 'i' } },
            { where: { $regex: `${query['q']}`, $options: 'i' } },
            { why: { $regex: `${query['q']}`, $options: 'i' } },
          ];
      return Audit.aggregate([
        {
          $facet: {
            audits: [
              {
                $match: {
                  type: { $in: JSON.parse(query['type']) },
                  createdAt: {
                    $gte: new Date(query['startDate']),
                    $lte: new Date(query['endDate']),
                  },
                  $or: JSON.parse(JSON.stringify(q)),
                },
              },
              { $limit: parseInt(query['limit']) },
              { $skip: (query['page'] - 1) * query['limit'] },
            ],
            apps: [
              {
                $group: {
                  _id: null,
                  apps: { $addToSet: "$appName" }
                }
              }, { "$unset": ["_id"] }
            ]
          },
        },
      ]).then((result: any) => res.json({ data: result }));
    });
```


#### MySQL

```javascript
Audit.addTracer('mysql', { host: 'localhost', user: 'root', 'password': 'root', database: 'myDB' });
```

##### Instantiate Mail Alerts  (Optional)

```javascript
DataTracer.configureAlert({
    'apiKey': 'abcdefghijklmnopqrstuvwxyz',
    'provider': 'sendgrid',
    'subject': `Error from ${APP_NAME}`,
    'from': 'achu10@live.in',
    'mailTo': 'achu10@live.in',
    'type': ['SEVERE']  // Severity types to trigger email
});
```

##### Sample usage

###### Definition

```javascript
    Audit.logEvent(
        type,
        what,
        subject,
        status,
        who,
        where,
        why,
        is,
        meta
    );
```

###### Example

```javascript
    Audit.logEvent(
        'INFO',
        'Ping',
        'api was triggered',
        'Successful',
        undefined,
        'app.js',
        'to Check Server status',
        'Event',
        {
            'key1': value,
            'key2': [
                {
                  'key21': 'value21'
                }
            ]
        }
    )
```
----------
    
### Examples
 * [Typescript Example](https://github.com/SAshwinAchu10/data-tracer/tree/master/examples/typescript)
 * [ReactJS Example](https://github.com/SAshwinAchu10/data-tracer/tree/master/examples/react) - WIP
 * [Javascript Example](https://github.com/SAshwinAchu10/data-tracer/tree/master/examples/javascript)


 ### Screenshot


[![N|Solid](https://github.com/SAshwinAchu10/data-tracer/blob/master/docs/1.png)](https://github.com/SAshwinAchu10/data-tracer/blob/master/docs/1.png)



### Roadmap [WIP]

 * Local file logging
 * Dashboard UI
 * QL for filtering Audit Events, Logs
 * Plugins like console, authorization etc.
 * ELK Integration
 * Monitoring
 * Tracing
 * etc...

---
_Source: https://npm.io/package/data-tracer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
