New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@lpgroup/feathers-counters-service

Package Overview
Dependencies
Maintainers
2
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lpgroup/feathers-counters-service

Services to handle counters in microservices

latest
Source
npmnpm
Version
1.10.2
Version published
Weekly downloads
155
434.48%
Maintainers
2
Weekly downloads
 
Created
Source

@lpgroup/feathers-counters-service

npm version Known VulnerabilitiesLicence MIT tested with jest codecov

Feathersjs hook that adds a counter key to data or result.

The package consists of the service counters and the hook counter. The hook will store the number of times a specific event has occured in a database through the service.

This funcionality can for example be used for statistics purpose. Counting the number of times GET has occured on a specific endpoint. Number of times a specific user has accessed a service. It can also be used to calculate a unique customer number on a customer endpoint on a specific organisation.

Install

Installation of the npm

npm install @lpgroup/feathers-counters-service
// or
yarn add @lpgroup/feathers-counters-service

The hook

beforeaftermethodsmultisource
yesyesallyessource

arguments

propertytypedefaultdescription
formatstringrequiredA format that makes the counter unique
periodFmtstringrequiredThe date period that the counter is counting. https://date-fns.org/v2.28.0/docs/format
keystringtrueThe name of the key in the returned json data/result
stepnumber1Number of steps to increase the counter each time, postive or negative.
descriptionstringnullDescription of the counter

The service

The service is required by the hook. To install it, modify feathers service file, app-ng/src/services/index.js, add the follwoing.

import { counters } from "@lpgroup/feathers-counters-service";

export default (app) => {
  /* ... */
  app.configure(counters);
};

Endpoints

POST: /counters
GET: /counters
GET: /counters/:alias
PATCH: /counters/:alias
PUT: /counters/:alias
DELETE: /counters/:alias

Object

{
  "alias": "status-visits-2021-11",
  "group": "status-visits",
  "period": "2021-11",
  "value": 50,
  "description": "status-visits"
  /* commonAttributes */
}

Example 1

Give each customer on an organisation a unique customer number, on the endpoint /organisations/:organisationAlias/customer.

The before hook will add the key customerNumber to data and store it in the database handled by the endpoint.

{organisationAlias} comes internally from the url in params.query.

import { counter } from "@lpgroup/feathers-counters-service";

export default {
  before: {
    all: [],
    find: [],
    get: [],
    create: [
      counter("{organisationAlias}-visitors", null, "customerNumber", 1, "Latest customerNumber"),
    ],
    update: [],
    patch: [],
    remove: [],
  },
};

Example 2

Calculate the number of times a user has accessed the GET method on /status?user=admin.

{user} comes internally from the query parameter in params.query.

import { counter } from "@lpgroup/feathers-counters-service";

export default {
  after: {
    all: [],
    find: [],
    get: [
      counter(
        "total_gets-{user}",
        null,
        "userAccesses",
        1,
        "Total number of calls done by a specific user",
      ),
    ],
    create: [],
    update: [],
    patch: [],
    remove: [],
  },
};

Example 3

Calculate number of calls during a month.

The counter will start from the beginning again every month. The statistics for earlier months will be stored in the /counters service.

import { counter } from "@lpgroup/feathers-counters-service";

export default {
  after: {
    all: [],
    find: [],
    get: [],
    create: [counter("visitors", "yyyy-MM", "visits", 1, "Number of visits during a month")],
    update: [],
    patch: [],
    remove: [],
  },
};

Example 4

Keep track of a stack of files, and for every create will increase 1 and for every delete will decrease 1.

import { counter } from "@lpgroup/feathers-counters-service";

export default {
  after: {
    all: [],
    find: [],
    get: [],
    create: [counter("files", null, "files", 1, "Total number of files")],
    update: [],
    patch: [],
    remove: [counter("files", null, "files", -1, "Total number of files")],
  },
};

Contribute

See contribute

License

MIT - See licence

Keywords

lpgroup

FAQs

Package last updated on 09 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts