Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@getanthill/event-source
Advanced tools
getanthill
Event-Sourcenpm install -S @getanthill/event-source
The following will be extended with the Event-Source functionalities.
// src/models/Users.ts
import { EventSourcedFactory } from '@getanthill/event-source';
/**
* This is the main reducer for your events.
* > f(state_{i}, event) = state_{i+1}
*/
const reducer = (state, event) => {
if (event.type === 'CREATED') {
return {
firstname: event.firstname,
};
}
return state;
};
export default class Users extends EventSourced('users', reducer) {
/**
* Create a new user
* @param {string} firstname The user firstname
* @return {Promise<object>} Updated state
*/
create(firstname) {
return this.handle(() => [
{
type: 'CREATED',
firstname,
},
]);
}
}
// src/business/users.ts
import Users from '../models/Users';
/**
* Create a user
*
* @param {object} db MongoDb connection
* @param {string} firstname User firstname
* @return {Promise<object>} State after success
*/
function createUser(db, firstname) {
const user = new Users(db, 1); // 1 = correlation_id
return user.create('John');
}
In your database, we will now have access to the events in the collection
users_events
:
db.users_events.find().pretty();
{
"type": "CREATED",
"correlation_id": 1,
"version": 0,
"firstname": "John",
"created_at": "2020-11-01T06:05:43.210Z"
}
and also the final resulting state of your object:
db.users.find().pretty();
{
"correlation_id": 1,
"version": 0,
"firstname": "John"
}
Now that you are able to have a fully Event-Source featured class, you can
read further on what is possible to create with this library and how to custom
a bit some features such as the correlation_id
naming.
FAQs
Event-sourced data store handling library
The npm package @getanthill/event-source receives a total of 83 weekly downloads. As such, @getanthill/event-source popularity was classified as not popular.
We found that @getanthill/event-source demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.