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

strapi-plugin-audit-log

v0.3.3

Published

Strapi - Audit log plugin

Downloads

88

Readme

Strapi - Audit log

Utilities for Strapi Headless CMS that allow searching across content types fields which have searchable property.

⏳ Installation

(Use yarn to install this plugin within your Strapi project (recommended). Install yarn with these docs.)

yarn add strapi-plugin-audit-log

Requirements

Complete installation requirements are exact same as for Strapi itself and can be found in the documentation under Installation Requirements.

Supported Strapi versions:

  • Strapi v3.3.4 (recently tested)
  • Strapi v3.x

(This plugin may work with the older Strapi versions, but these are not tested nor officially supported at this time.)

We recommend always using the latest version of Strapi to start your new projects.

Features

Config

  • Config in config/middleware.js we have to set:
 'audit-log': {
      enabled: true,
      exclude: []
      map: [
        {
          pluginName: 'content-manager',
          serviceName: 'contentmanager',
          decorate: boolean,
          
          Class: ExampleClass,
          fetchSingle: 'methodName',
        },
      ]
    },

where:

  • enabled - to enable that middleware and plugin
  • map - contain configs which endpoint should handle by audit-log middleware
    • pluginName - plugin name which have log for this endpoint to it from strapi object, and first part url to requests
    • serviceName - service which on have business logic for this plugin
    • decorate - boolean which told audit log which path should be use to handle changes events or service decorate if we set it to true we should return from service new entity to compare to old one handled and cached by audit log, otherwise we should provide Class property where we can handle events from our service example for navigation
    • fetchSingle - method to fetch a single entity to compare snapshot for REST API, audit log will paste entityId as parameter
    • Class - a class which one handle audit-log logic, should extend Base class from this plugin this class have to implement method run which one will be call after finish other middlewares, this method have signature:
       abstract async run(method: string, ctx: KoaContext, config: ServiceConfig): Promise<void>;
    and in this method we should call save from Base class to save data in a database:
        await this.save(
          cleaningData.delete.id,
          AvailableAction.DELETE,
          ctx.params.model,
          diffs,
        );
    we can set couple types actions:
        export enum AvailableAction {
          CREATE = 'CREATE',
          UPDATE = 'UPDATE',
          DELETE = 'DELETE',
          // for batch actions
          UPDATE_REMOVE = 'UPDATE_REMOVE',
          UPDATE_CREATE = 'UPDATE_CREATE',
          CREATE_UPDATE = 'CREATE_UPDATE',
          CREATE_REMOVE = 'CREATE_REMOVE',
          REMOVE_UPDATE = 'REMOVE_UPDATE',
          REMOVE_CREATE = 'REMOVE_CREATE',
          CREATE_UPDATE_REMOVE = 'CREATE_UPDATE_REMOVE',
          CREATE_REMOVE_UPDATE = 'CREATE_REMOVE_UPDATE',
          UPDATE_CREATE_REMOVE = 'UPDATE_CREATE_REMOVE',
          UPDATE_REMOVE_CREATE = 'UPDATE_REMOVE_CREATE',
          REMOVE_UPDATE_CREATE = 'REMOVE_UPDATE_CREATE',
          REMOVE_CREATE_UPDATE = 'REMOVE_CREATE_UPDATE',
        }
    
    • fetchSingle - method name from service which one we can use to fetch full entity to get, we need this to create snapshots
    • decorate - flag for audit log how we collect data, with this flag audit log will decorate our service and save results from service methods in entities to compare changes
  • It will create a collection audit_log in a database where we can find information about the changes out model in the database, by default, we support the content-manager plugin.
  • We can fetch information about available versions some entity via endpoint:
/audit-log?model={ourModelName}&id={entityId}

Example response:

REQUEST: GET http://HOST/audit-log?model=example&id=1
RESPONSE:
{
    "results": [
        {
            "id": 13,
            "originId": "1",
            "modelName": "example",
            "action": "UPDATE",
            "timestamp": "2020-11-09T09:31:42.105Z"
        },
        {
            "id": 14,
            "originId": "1",
            "modelName": "example",
            "action": "UPDATE",
            "timestamp": "2020-11-09T09:31:52.497Z"
        },
        {
            "id": 15,
            "originId": "1",
            "modelName": "example",
            "action": "UPDATE",
            "timestamp": "2020-11-09T09:47:19.830Z"
        }
    ]
}
  • To fetch some history version we can use endpoint:
/audit-log/{originId}/snapshots?model={modelName}&version={versionId}

Example response:

REQUEST: GET http://HOST/audit-log/13/snapshots?model=example&id=1
RESPONSE:
{
    "entity": {
        "id": 1,
        "name": "Example Data",
        "visible": true,
        "created_by": null,
    }
}

Under entity we can find our historic version.

Contributing

Feel free to fork and make a Pull Request to this plugin project. All the input is warmly welcome!

Community support

For general help using Strapi, please refer to the official Strapi documentation. For additional help, you can use one of these channels to ask a question:

  • Email us We are always glad to help.
  • Slack We're present on official Strapi slack workspace.
  • GitHub (Bug reports, Contributions, Questions and Discussions)

License

MIT License Copyright (c) 2020 VirtusLab Sp. z o.o. & Strapi Solutions.