npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-diff-audit

v1.0.0

Published

Detect changes and generate audit events for a series of JSON objects

Downloads

58

Readme

JSON diff audit

json-diff-audit is a Node.js library that compares JSON objects consecutively, identifies differences, and generates detailed audit records for easy reporting and tracking changes.

Table of Contents

Install

npm:

npm install json-diff-audit

Usage

Node

const { auditEventTransformer } = require('json-diff-audit')

const record1 = { 
  employee : {
    name: "John Smith",
  },
  date: "04-17-2023 9:16:2 pm",
  userId: "klewis",
}

const record2 = {
  employee : {
    name: "Jane Thomas",
  },
  date: "04-21-2023 10:23:2 am",
  userId: "mtimms",
}

const result = auditEventTransformer.process([record1, record2], "employee")

console.info(JSON.stringify(result))

Input

auditEventTransformer.process(arg1, arg2) 

arg1:  Collection of domain objects to compare

arg2:  Domain field for comparisons, defaults to "data"

Output

[
  {
    "path":"name",
    "user":"mtimms",
    "dateAndTime":"04-21-2023 10:23:2 am",
    "field":"name",
    "action":"update",
    "oldValue":"John Smith",
    "newValue":"Jane Thomas"
  }
]

The output shows that an update was made to the name field, going from John Smith to Jane Thomas, and was made by user mtimms on 04-21-2023 at 10:23:2 am.

How it works

The input is a collection of records. Each record should have 3 fields

| Field | Description | |------| ---- | | userId | the user that made the changes to the current object | | date | the date and time the change was made | | < domain object > | the key name to the domain object that will be compared, defaults to 'data' |

The processing will compare each record in the collection to the next, they are assumed to be ordered by date. A list of deltas is calculated and turned into a collection of audit records. Each audit record will contain the following fields:

| Field | Description | |------| ---- | | user | the user that made the changes to the current object | | dateAndTime | the date and time the change was made | | field | the field key name that was affected | | action | the field in question was either an add, update, or delete | | oldValue | if an action is either update or delete, this field indicates the previous value | | newValue | if an action is either an update or add, this field indicates the new value | | path | the full path in dot notation to the affected field |

Logging

By default, json-diff-audit will only log errors encountered during it's function execution. Additional debugging output can be conditionally triggered by setting the environment variable json_diff_audit__debug = true.

Notes

  1. The path in the response is experimental at this time, certain cases with arrays are still being considered
  2. Comparison of domain objects is currently done by order in the collection, not by date.