
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
@lpgroup/feathers-counters-service
Advanced tools
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.
Installation of the npm
npm install @lpgroup/feathers-counters-service
// or
yarn add @lpgroup/feathers-counters-service
| before | after | methods | multi | source |
|---|---|---|---|---|
| yes | yes | all | yes | source |
| property | type | default | description |
|---|---|---|---|
format | string | required | A format that makes the counter unique |
periodFmt | string | required | The date period that the counter is counting. https://date-fns.org/v2.28.0/docs/format |
key | string | true | The name of the key in the returned json data/result |
step | number | 1 | Number of steps to increase the counter each time, postive or negative. |
description | string | null | Description of the counter |
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);
};
POST: /counters
GET: /counters
GET: /counters/:alias
PATCH: /counters/:alias
PUT: /counters/:alias
DELETE: /counters/:alias
{
"alias": "status-visits-2021-11",
"group": "status-visits",
"period": "2021-11",
"value": 50,
"description": "status-visits"
/* commonAttributes */
}
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: [],
},
};
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: [],
},
};
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: [],
},
};
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")],
},
};
See contribute
MIT - See licence
FAQs
Services to handle counters in microservices
The npm package @lpgroup/feathers-counters-service receives a total of 155 weekly downloads. As such, @lpgroup/feathers-counters-service popularity was classified as not popular.
We found that @lpgroup/feathers-counters-service demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

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.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.