
Research
Supply Chain Attack on Axios Pulls Malicious Dependency from npm
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.
Minimal (neto) implementation of a finite state machine in javascript
Please report any bugs or feature requests, thanks!
Generates a finite state machine. States can be defined, transitions to these states can be performed and parameters to the actions can be passed. Supports synchronous and asynchronous actions.
npm install machineto
function action() {
// Do Something
}
var machineto = require("machineto");
var sm = new machineto("state1", {
"state1": { "event": { action: action, nextState: "state2" } },
"state2": { "event": { action: action } }
}, {
"logger": true
});
sm.fire("event");
<script type="text/javascript" src="path/to/machineto.min.js"></script>
<script type="text/javascript">
function action() {
// Do Something
}
var sm = new Machineto("state1", {
"state1": { "event": { action: action, nextState: "state2" } },
"state2": { "event": { action: action } }
});
sm.fire("event");
</script>
require.config({
paths: {
"machineto": "path/to/machineto",
}
});
define(["machineto"], function (machineto) {
function action() {
// Do Something
}
var sm = new machineto("state1", {
"state1": { "event": { action: action, nextState: "state2" } },
"state2": { "event": { action: action } }
});
sm.fire("event");
});
state-machine.js
importScripts("path/to/machineto.min.js");
function action() {
// Do Something
}
var sm = new Machineto("state1", {
"state1": { "event": { action: action, nextState: "state2" } },
"state2": { "event": { action: action } }
}, {
"logger": true
});
onmessage = function (event) {
if (event.data.request &&
event.data.request.name) {
postMessage({
"response": sm[event.data.request.name] &&
sm[event.data.request.name].apply(this, event.data.request.params)
});
}
};
example.html
<script type="text/javascript">
var workerSM = new Worker("path/to/state-machine.js");
workerSM.onmessage = function (event) {
console.log("State Machine Worker said: " + JSON.stringify(event.data));
};
workerSM.postMessage({ request: {
"name": "getCurrentState"
}});
workerSM.postMessage({ request: {
"name": "fire",
"params": [
"event"
]
}});
workerSM.postMessage({ request: {
"name": "getCurrentState"
}});
</script>
function on() {
// Do Something
}
function off() {
// Do Something
}
function allow() {
// Do Something
}
function sleep(callback) {
// Do Something
}
var sm = new Machineto("off", {
"off": {
"setCode": { action: allow },
"turnOn": { action: on, nextState: "on" },
"turnSleep": { action: sleep, async: true, nextState: "sleep" }
},
"on": {
"setCode": { action: allow },
"turnOff": { action: off, nextState: "off" }
},
"sleep": {
"turnOn": { action: on, nextState: "on" },
}
}, {
"logger": console
});
sm.fire("setCode", "#1234"); // invokes allow("#1234") and returns true
sm.getCurrentState(); // returns "off" (current state)
sm.fire("turnOn", "now!"); // invokes on("now!") and returns true
sm.getCurrentState(); // returns "on" (current state)
sm.fire("turnOn", "check!"); // returns false (no action was called)
sm.getCurrentState(); // returns "on" (current state)
sm.fire("setCode", "1234#"); // invokes allow("1234#") and returns true
sm.getCurrentState(); // returns "on" (current state)
sm.fire("setCode", "#"); // invokes allow("#") and returns true
sm.getCurrentState(); // returns "on" (current state)
sm.fire("turnOff", "bye!"); // invokes off("bye!") and returns true
sm.getCurrentState(); // returns "off" (current state)
sm.fire("turnSleep", callback); // invokes sleep(callback) and returns true
sm.getCurrentState(); // returns "off" (current state)
sm.getCurrentState(); // returns "sleep" (current state) after callback is invoked
Note: for more examples look at the tests
Find a bug? Have a feature request? Please create an Issue. If you find this project useful please consider "starring" it to show your support!
Itai Koren (@itkoren) itkoren@gmail.com
Special thanks to @miki2826, for helping to design and create this piece
Copyright (c) 2014 Itai Koren (@itkoren) itkoren@gmail.com, contributors.
This file was generated by grunt-verb on November 23, 2014.
FAQs
Minimal (neto) implementation of a finite state machine in javascript
We found that machineto demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.