1.0.0 • Published 6 years ago

actions-tracker v1.0.0

Weekly downloads
6
License
ISC
Repository
github
Last release
6 years ago

actions-tracker

TypeScript library to build and manage action. The described actions can be of every type, like post creation, users' login, system update, file deleted and every types you need.

This package is useful for setting up a full configurable data container. Once you had build your actions, the following packages help you save them in different database:

To use them you simply must:

  • create the action and configure the data manager installed
  • pass the action to the data manager installed
  • invoke save() method on the data manager.

Quickstart

npm package: https://www.npmjs.com/package/actions-tracker

#package installation
npm install actions-tracker

Structure

Every actions can be summary as follow:

  • who does the actions? (-> source)
  • who is the target? (-> target)
  • what is the action? (-> operation))

Those element is essential for rebuild the action. However sometimes is not possible figure every actions only by those simple attribute: every element has an extra object caller "otherInformation", where it's possbile insert key/value information.

Interface implementation

The entire package is developed with interface, but there are a simple implementation with getter and setter.

Using this interface structure is possible to redefine the action's element logic and functionality. It's also possible adapt the current object in action's element, simply implementing the interface.

Example (typescript):

In a blog always exist the users, that probably do a lot of action during the session. Why create a new and empty actor? We can directly use user as actor.

import {actionInterface, InformationContent} from './node_modules/actions-tracker';
import {types} from "./node_modules/actions-tracker";

export class User extends InformationContent implements actionInterface.ActorInterface {

    id: number;
    email: string;

    
    ....
    


    getHumanIdentifier(): number | string | undefined {
        return this.email;
    }

    getIdentifier(): number | string {
        return this.id;
    }

    getType(): number | string | undefined {
        return 'user';
    }

    getValues(): types.ActorType {
        return {
            identifier: this.id,
            humanIdentifier: this.email,
            type: 'user',
            otherInformation: this.getAllInformationString()
        }
    }
}

Now user can be use as actor inside the actions.

The same implementation can be use to create new operations and for the entire action.

Configuration

When a new log is created, it's possible to set configuration and customize the functionality and data check. The configuration format is:

{
   "actorsType": <string[]>,
   "moduleEnabled": <string[]>,
   "actionEnabled": <string[]>,
   "dataManager": <ActionDataManagerInterface>
}

With the first three arrays you have the possibility to set the enable values for the attributes: when you try to save and the attribute values are not valid, the function fail.

dataManager must be an object that implements ActionDataManagerInterface, an object able to manipulate action's data Without that, every data's action like save will fail. At the start of this README there is a list of some package that implements it.

Data types

Data format of the action's elements; fields with ending * are required.

action

{
  "actors*": {
    "source*": <actor-format>,
    "actorOtherInformation": <otherInformation-format>,
    "target": <actor-format>,
  },
  "operation*": {
    "privacy": <boolean>,
    "action" : <string>,
    "module" : <string>,
    "otherInformation" : <otherInformation-format>
  },
  "actionInformation": <otherInformation-format>  
}

actor

{
  "identifier*": <number|string>,
  "humanIdentifier": <number|string>,
  "type": <string>,
  "otherInformation" : <otherInformation-format>
}

operation

{
  "privacy": <boolean>,
  "action*" : <string>,
  "module" : <string>,
  "otherInformation" : <otherInformation-format>
}

otherInformation

{
  "key-1": "value-1",
  "key-2": "value-2",
  ...
}

Multi-level object aren't supported yet.

Example

{
  "actors": {
    "source": {
      "identifier": 32847,
      "humanIdentifier": "example@email.it",
      "type": "user",
      "otherInformation" : {
        "actualRole": "admin"
      }
    }, 
    "actorOtherInformation": {
      "by": "yellow button"
    },
    "target": {
      "identifier": 213,
      "humanIdentifier": "Post title",
      "type": "post",
      "otherInformation" : {
        "currentLang": "en"
      }
    }
  },
  "operation": {
    "privacy": false,
    "action" : "create",
    "module" : "blogPost",
    "otherInformation" : {}
  },
  "actionInformation": {
    "time": 1239872139
  }
}
1.0.0

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago